Products Email Field

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
Barrowboy
Forum Members
Forum Members
Posts: 223
Joined: Mon Dec 16, 2013 4:09 pm

Products Email Field

Post by Barrowboy »

Hi
Is it possible to create a field in products module that would recognise an email address?

The only way I have managed to do it at the moment is in a text field by adding the full ref.
<a href="mailto:somebody@me.com">Joe Bloggs</a>

This works but you need some coding experience to keep adding.

What I was looking for is just to add the email address and the system adds the rest.

Any ideas you guys?

Thanks
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: Products Email Field

Post by JohnnyB »

You might use some regex matching on the field inside of the template. Then, if it is known to be an email address, wrap it in your mailto link.

You can use the regex with smarty / php or via javascript on the client side.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: Products Email Field

Post by paulbaker »

Or try {mailto address="asdf@asdf.com" encode="javascript"} which uses JS to try to hide email from spam harvesters.
Barrowboy
Forum Members
Forum Members
Posts: 223
Joined: Mon Dec 16, 2013 4:09 pm

Re: Products Email Field

Post by Barrowboy »

Hi Power poster

I like this idea but were and how would it be used in relation to the field used i.e. Text Input.

Does it just go in the template?

Cheers.
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: Products Email Field

Post by paulbaker »

Not sure, try it and see ;) you may find the { code } is not parsed and so it's not a solution for you.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Products Email Field

Post by velden »

What about adding two normal text input fields and inside template build the link yourself? That would be the normal cmsms/template/smarty way I guess:

Assuming you add two fields: 'emailname' and 'emailaddress':

Code: Select all

<a href="mailto:{$entry->fields.emailaddress->value}">{$entry->fields.emailname->value}</a>
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Products Email Field

Post by calguy1000 »

{if is_email($entry->fields.emailaddress->value)}
<a href="mailto:{$entry->fields.emailaddress->value}">email the guy</a>
{else}
... something else ...
{/if}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: Products Email Field

Post by JohnnyB »

Not tested.

You would look in the frontend template for the custom field you want to make an email address.

{assign var='email_regex' value='/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/'}

*** I might have the regex syntax wrong for the value='' but it is a common regex to find an email address....

{if $My.Custom.Products.Field.Value|preg_match:email_regex}
{mailto address=$My.Custom.Products.Field.Value encode=javascript}
{/if}

That is the basic logic. You'll need to supply your custom field value in there and like I said it is not tested and I may have some stuff wrong in there. But, that would be the idea to test if the field contains an email address and if so, make the value into a clickable email address on the page...
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: Products Email Field

Post by JohnnyB »

Oh Snap!
I didn't know about the is_email function.
Much easier than trying regex stuff.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
Barrowboy
Forum Members
Forum Members
Posts: 223
Joined: Mon Dec 16, 2013 4:09 pm

Re: Products Email Field

Post by Barrowboy »

Hi All

Thanks for all your help.

Not sure what was meant by not describing my problem thought I had done that in my first message.

Anyway I choose the idea of having two text inputs and used this in my template.
<span class="email">Email:-</span> {if is_email($entry->fields.emailaddress->value)}
<a href="mailto:{$entry->fields.emailaddress->value}"> {$entry->fields.emailname->value}</a>
{/if}

Works a treat. Having a second text input allows me to have a different name from the email i.e. Manager, Editor, Secretary etc.

Thanks again till the next time.
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: Products Email Field

Post by JohnnyB »

Not sure what was meant by not describing my problem thought I had done that in my first message.
.... That's just his default profile signature... :P
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
Post Reply

Return to “Modules/Add-Ons”