Jump to content

insert mailto hyperlink into textarea


danielholanda
 Share

Recommended Posts

Hello everybody!

I've actually created already a web that works perfectly with processwire. There only some dumb questions which I do not figure out by myself. This is one of them...

I have a field called "contact" where obviously the client will insert her contact details. The client wants that if she inserts and email it will be a hyperlink. She doesn't need a form or anything too fancy. She would be ok with a mailto applied to it. The field is in this moment applied as a textarea. The details she has "Newlines to XHTML Line Breaks" applied.

Is there a special way so I can apple a simple html link with a hyperlink with mailto bla bla bla. I would like the most simple workout as possible.

Really thanks!!! Once this is finished and some other details I will show to the team!

Link to comment
Share on other sites

or maybe I misunderstood your question. Have you tried making the textarea Inputfield type to use TinyMCE? Then they could add an email link themselves (but would have to remember to add the mailto: before)

Thanks for the answer... I see that if you use TinyMCE you can edit directly in the text box. My client isn't the biggest genius with that and would like to avoid her placing codes herself. If I have this text for the contact field:

Rozenstraat 158hs

Postbus 15372

1001 MJ Amsterdam

t: +31 (0)20 77 24 258

e: info@provisionevents.nl

w: www.provisionevents.nl

Can I place it as an email field? Will this detect the emails inside the text? I suppose not...

If I placed TinyMCE she would have to write this herself for example, right?:

Rozenstraat 158hs

Postbus 15372

1001 MJ Amsterdam

t: +31 (0)20 77 24 258

e: <a href="mailto:info@provisionevents.nl">info@provisionevents.nl</a>

w: www.provisionevents.nl

Link to comment
Share on other sites

  • 11 months later...

Hi,

I changed the preg_replace parameters a bit. Perhaps someone can use it.

Cause if a user sets a "normal" link to an email address the result is:

<a href="foo@foo.bar">email</a>

The reg ex is looking for any link like that, and makes it to a correct mail link.

$body = preg_replace('/\<a href="(\S+@\S+\.\S+)\>/i', '<a href="mailto:$1>', $page->body);
echo $body;

Result is:

<a href="mailto:foo@foo.bar">email</a>

I'm not the super expert for regular expressions. Perhaps someone can check, if this is correct. :rolleyes: For me it seems to work.

Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...