Good morning.
Got a really infuriating problem I just can't seem to solve. Let me try to explain.
I have a contact form on my website. The form works in three sections.
1) http://www.didymus.org.uk/new_contact/contact.php
This asks for a visitor's name, e-mail address and comments. Visitors also have to enter a CAPTCHA code before clicking SUBMIT which passes these fields to;
2) http://www.didymus.org.uk/new_contact/check.php
Here's where the problem occurs. When the <textarea> named comments from step 1 is displayed in the <textarea> of the same name in step 2, it adds /r/n if the user has used a carriage return.
So typing:
LINE 1
LINE 2
LINE 3
in step 1 is displayed in step 2 as
LINE1\r\nLINE2\r\nLINE3
The visitor then confirms the information and presses SUBMIT again. The data is then sent to SENDMAIL.PHP.
3) http://www.didymus.org.uk/new_contact/sendmail.php
Sends the e-mail and displays a confirmation message.
Feel free to play around with my contact page to see what I mean.
In short, what I'm asking is what code would I use in step 2 (CHECK.PHP) to remove the unwanted /r/n and (preferably) convert this code in to a simple HTML carriage return?
Many thanks in advance for your help.
KD.
Problems with \r\n in form
Moderator: General Moderators
Re: Problems with \r\n in form
Hi
I had the same problem when posting data from one textarea to another. I used
But When Displaying in a html element e.g. a paragraph (<p></p>) I used
Here are the links to the manual
stripslashes
htmlentities
nl2br
I had the same problem when posting data from one textarea to another. I used
Code: Select all
stripslashes(htmlentities($_POST['My_Post_Data']))Code: Select all
nl2br($_POST['My_Post_Data'])stripslashes
htmlentities
nl2br
Re: Problems with \r\n in form
What can I say? That drove me mad for the last day or so.
I used
Thank you. Thank you. Thank you!
You're a star. Don't let anyone tell you differently!
KD.
I used
and it worked perfectly.= stripslashes(htmlentities($_POST['comments']))
Thank you. Thank you. Thank you!
You're a star. Don't let anyone tell you differently!
KD.
Re: Problems with \r\n in form
Okay. So let's take this one step further.
So long as my visitor passes the CAPTCHA test, he / she is given the option of either submitting the completed form OR clicking a MAILTO: link to use their own e-mail client.
I've used the following HTML:
Now I've used the stripslashes command already so that $comments2 is formatted correctly in another textarea.
Is there a way of preserving the formatting so that the comments are formatted correctly for the body of an e-mail?
I thought of using:
but that gives <br /> all the way through.
Sorry. I know I'm a pain!
KD.
So long as my visitor passes the CAPTCHA test, he / she is given the option of either submitting the completed form OR clicking a MAILTO: link to use their own e-mail client.
I've used the following HTML:
Code: Select all
If you'd prefer to contact us using your own e-mail client, click <a href='mailto:$email1?subject=E-Mail from http://www.didymus.org.uk&body=$comments2'>HERE</a>Is there a way of preserving the formatting so that the comments are formatted correctly for the body of an e-mail?
I thought of using:
Code: Select all
$comments3 = nl2br($_GET['comments'])Sorry. I know I'm a pain!
KD.
Re: Problems with \r\n in form
Unless you're sending the email as html, you don't need to use nl2br(). New lines display as new lines.
Re: Problems with \r\n in form
Marvellous. My Outlook is set to use HTML by default. That explains it!
Many thanks for your answer.
KD.
Many thanks for your answer.
KD.