Products Email Field
Products Email Field
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
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
Re: Products Email Field
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.
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.
--
--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
Re: Products Email Field
Or try {mailto address="asdf@asdf.com" encode="javascript"} which uses JS to try to hide email from spam harvesters.
Re: Products Email Field
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.
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.
Re: Products Email Field
Not sure, try it and see
you may find the { code } is not parsed and so it's not a solution for you.
Re: Products Email Field
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':
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

- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
Re: Products Email Field
{if is_email($entry->fields.emailaddress->value)}
<a href="mailto:{$entry->fields.emailaddress->value}">email the guy</a>
{else}
... something else ...
{/if}
<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.
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.
Re: Products Email Field
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...
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.
--
--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
Re: Products Email Field
Oh Snap!
I didn't know about the is_email function.
Much easier than trying regex stuff.
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.
--
--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
Re: Products Email Field
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.
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.
Re: Products Email Field
.... That's just his default profile signature...Not sure what was meant by not describing my problem thought I had done that in my first message.
"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.
--
--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--


