View Full Version : PHPFormGenerator - textarea - help!!

07-01-2005, 05:15 PM
Hi there!

I have used Phpformgenerator via fantastico/cpanel and is working very well. Emails are being recieved fine, no problems at all.

Just one minor thing that is annoying me though.

The message area where customers type their enquiry into - Ie: the Textarea tag.. is sending me the message with wierd code where there are line breaks. In the process.php there is a line of code that has "&nbsp;<br />" in it, which looks like the culprit.

Here's the full line of code it came from:

$Message=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Message);if($YourName=="" || $EmailAddress=="" || $Message=="" ){

Here's what the Thank You page displayed upon submitting the email:

just testing this page out to see if it works.

this is a test line
so is this line





Then here's what I am getting via email - bear in mind it was a test email to myself via my enquiry page.

Your Name: jack
Business Name:
Email Address: jack@jack.com
Contact Number: 0403 123 456
Message: just testing this page out to see if it works.&nbsp;<br />&nbsp;<br />this is a test line&nbsp;<br />so is this line&nbsp;<br />&nbsp;<br />123&nbsp;<br />123&nbsp;<br />&nbsp;<br />123&nbsp;<br />&nbsp;<br />123

Any ideas as to what might be causing those <br /> and &nbsp being inserted into the Message/textarea?

The html doesnt show up in my webmail service, but shows up in outlook express. This is actually a HUGE favour for a good friend of mine, and she doesnt understand HTML and dislikes webmail, and prefers outlook express :(


Thanks so much,

07-01-2005, 06:01 PM
Hmm, what's happening is that when you type in a textarea, a line break doesn't produce the <br /> tag that is required to format the text properly when it's output back to the page.

A way around this problem is to comment out the line:

[/php]// $Message=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Message);if($YourName=="" || $EmailAddress=="" || $Message=="" ){[/php]

Then find the part of the script that outputs the html confirmation page and instead of echoing the variable, echo it via the nl2br() function, eg if you see this:

echo $Message;

replace it with:

echo nl2br($message);

That should insert the line breaks to make the html work without removing the special line breaks that format the email message.

07-01-2005, 06:56 PM
Thanks heaps mate!!!

This is how my code looks now for anyone else that has the same problem as me. I just don't understand why the author of the script couldn't have seen this being a problem, especially if you are implementing this for people who cant understand html when they get their enquiries!! I am doing this for a good friend of mine who doesnt know html, and just found it so difficult reading her enquiry emails via her site with html coding at every line break spacing.

I actually emailed the author 4 days ago, and no reply at all. I've posted to about 4 sites tonight, and you are the only one who has given me exactly the correct solution.

Thank you sooooooooo much from all the way from West. Australia!

$error="The following errors occured while processing your form input.<ul>";
//$Message=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Message);
if($YourName=="" || $EmailAddress=="" || $Message=="" ){
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$EmailAddress)){
$error.="<li>Invalid email address entered";
if($errors==1) echo $error;
$message="Your Name: ".$YourName."
Business Name: ".$BusinessName."
Email Address: ".$EmailAddress."
Contact Number: ".$ContactNumber."
Message: ".$Message."
$message = stripslashes($message);
mail("tabnlala@optusnet.com.au","Enquiry Submitted at your website",$message,"From: $EmailAddress");

<!-- This is the content of the Thank you page, be careful while changing it -->

<h2>Thank you!</h2>

<table width=50%>
<tr><td>Your Name: </td><td> <?php echo $YourName; ?> </td></tr>
<tr><td>Business Name: </td><td> <?php echo $BusinessName; ?> </td></tr>
<tr><td>Email Address: </td><td> <?php echo $EmailAddress; ?> </td></tr>
<tr><td>Contact Number: </td><td> <?php echo $ContactNumber; ?> </td></tr>
<tr><td>Message: </td><td> <?php echo nl2br($Message); ?> </td></tr>
<!-- Do not change anything below this line -->


EDIT: just adding - what was the main purpose of that particular line I commented out anyway? I am a php newbie, so please excuse my ignorance, I just found it totally unnecessary to even have it included in the first place.

EDIT: Just wondering, are those $ variables/functions (or whatever the correct term is..) case sensitive? wld it have matted if i spelt $Message as $message?


07-01-2005, 10:47 PM
Well an alternative would be to move that line after the mail() function. The code on that line replace \n or \r or \n\r into a nonbreakable space (&nbsp;) and a <br /> tag.