Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHPFormGenerator - textarea - help!!

    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

    123
    123

    123

    123

    ---------------------------------------------------------------------------------------------

    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

    All replies GREATLY APPRECIATED!!

    Thanks so much,
    Julian

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    echo $Message
    replace it with:

    PHP Code:
    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.

  • #3
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

    PHP Code:
    <?php
    include("global.inc.php");
    $errors=0;
    $error="The following errors occured while processing your form input.<ul>";
    pt_register('POST','YourName');
    pt_register('POST','BusinessName');
    pt_register('POST','EmailAddress');
    pt_register('POST','ContactNumber');
    pt_register('POST','Message');
    //$Message=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />", $Message);
    if($YourName=="" || $EmailAddress=="" || $Message=="" ){
    $errors=1;
    $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";
    $errors=1;
    }
    if(
    $errors==1) echo $error;
    else{
    $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
    $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>
    </table>
    <!-- Do not change anything below this line -->

    <?php 
    }
    ?>
    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?


    Cheers!!!
    Julian
    Last edited by praet123; 07-01-2005 at 07:25 PM.

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •