Replace form inputs with <br> tags

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dameon99
    New Member
    • Jun 2007
    • 57

    #1

    Replace form inputs with <br> tags

    HI, Im new to PHP completely but Im wanting to format the inputs for $order and $specialinstruc tions so that the /n of input is replaced with <br /> tags in the html. Ive heard about using nl2br() and Ive tried a rediculous number of things to try to make it work and use it properly from entries from many different forums. Can anyone please have a look at my code and let me know how I can implement this?!

    [code=php]
    <?php

    // multiple recipients
    $newcustomer = $_POST["newcustome r"];
    $name = $_POST["name"];
    $accountnumber = $_POST["accountnum ber"];
    $deliveryaddres s = $_POST["deliveryaddres s"];
    $nameoforderer = $_POST["nameoforde rer"];
    $phone = $_POST["phone"];
    $email = $_POST["email"];
    $deliverydate = $_POST["deliveryda te"];
    $deliverytime = $_POST["deliveryti me"];
    $order = $_POST["order"];
    $specialinstruc tions = $_POST["specialinstruc tions"];
    $billing = $_POST["billing"];

    // multiple recipients
    $to = 'andrew@domain. com';
    //$to = 'you@domain.com .au' . ', '; // note the comma
    //$to .= 'wez@example.co m';

    // subject
    $subject = 'your_domain Website Order';

    // message
    $message = '
    <html>
    <head>
    <title>your_dom ain Website Order</title>
    </head>
    <body>
    <table width=450 border=0 cellspacing=6 cellpadding=0>
    <tr>
    <td WIDTH=182>&nbsp ;</td>
    <td WIDTH=268>
    <center>
    <h3 ALIGN=LEFT>your _domain Website Order</h3>
    </center>
    </td>
    </tr>
    <tr>
    <td WIDTH=182>
    <p ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>New Customer:</font></p>
    </td>
    <td WIDTH=268>
    <div ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>
    <strong>'.$newc ustomer.'</strong></font></div>
    </td>
    </tr>
    <tr>
    <td WIDTH=182>
    <p ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>Customer Account Name:</font></p>
    </td>
    <td WIDTH=268>
    <div ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>
    <strong>'.$name .'</strong></font></div>
    </td>
    </tr>
    <tr>
    <td WIDTH=182>
    <p ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>Account Number:</font></p>
    </td>
    <td WIDTH=268>
    <div ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>
    <strong>'.$acco untnumber.'</strong> </font></div>
    </td>
    </tr>
    <tr>
    <td WIDTH=182>
    <p ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>Delivery Address:</font></p>
    </td>
    <td WIDTH=268>
    <div ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>
    <strong>'.$deli veryaddress.'</strong> </font></div>
    </td>
    </tr>
    <tr>
    <td WIDTH=182>
    <p ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>Name of Person Ordering:</font></p>
    </td>
    <td WIDTH=268>
    <div ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>
    <strong>'.$name oforderer.'</strong> </font></div>
    </td>
    </tr>
    <tr>
    <td WIDTH=182>
    <p ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>Phone:</font></p>
    </td>
    <td WIDTH=268>
    <div ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>
    <strong>'.$phon e.'</strong> </font></div>
    </td>
    </tr>
    <tr>
    <td WIDTH=182>
    <p ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>Email:<b r>
    </font></p>
    </td>
    <td WIDTH=268>
    <div ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>
    <strong>'.$emai l.'</strong> </font></div>
    </td>
    </tr>
    <tr>
    <td WIDTH=182>
    <p ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>Delivery Date:<br>
    </font></p>
    </td>
    <td WIDTH=268>
    <div ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>
    <strong>'.$deli verydate.'</strong> </font></div>
    </td>
    </tr>
    <tr>
    <td WIDTH=182> <font FACE=Arial, Helvetica, sans-serif SIZE=2>Delivery Time:<br>
    </font></td>
    <td WIDTH=268>
    <div ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>
    <strong>'.$deli verytime.'</strong> </font></div>
    </td>
    </tr>
    <tr>
    <td WIDTH=182 valign="top">

    <p ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>Order:<b r>
    </font></p>
    </td>
    <td WIDTH=268>
    <div ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>
    <strong>'.$orde r.'</strong> </font></div>
    </td>
    </tr>
    <tr>
    <td WIDTH=182>

    <p ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>Special Instructions:<b r>
    </font></p>
    </td>
    <td WIDTH=268>
    <div ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>
    <strong>'.$spec ialinstructions .'</strong> </font></div>
    </td>
    </tr>

    <tr>
    <td WIDTH=182>

    <p ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>Billing: <br>
    </font></p>
    </td>
    <td WIDTH=268>
    <div ALIGN=LEFT><fon t FACE=Arial, Helvetica, sans-serif SIZE=2>
    <strong>'.$bill ing.'</strong> </font></div>
    </td>
    </tr>

    </table>



    </body>
    </html>
    ';

    // To send HTML mail, the Content-type header must be set
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    // Additional headers

    $headers .= 'From: your_domain Website <info@your_doma in.com.au>' . "\r\n";

    // Mail it
    mail($to, $subject, $message, $headers);
    header("Locatio n: http://www.your_domain .com.au/thankyou.html") ;
    ?>[/code]
    Last edited by ak1dnar; Aug 13 '07, 04:01 AM. Reason: Replaced(Commercial)emails,web sites with some sample values
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    Thread Title *Help!!!* Replaced.
    What makes a Good Thread Title

    Comment

    • Dameon99
      New Member
      • Jun 2007
      • 57

      #3
      Thanks.. I think.. I really just need help with my code.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Dameon.

        What do you want your code to do? Give an example.
        What is your code doing that you don't want it to do? Give an example.
        What is your code *not* doing that it is supposed to? Give an example.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Originally posted by Dameon99
          HI, Im new to PHP completely but Im wanting to format the inputs for $order and $specialinstruc tions so that the /n of input is replaced with <br />
          ...
          Well, you probbly want to start by using '\n' rather than '/n'.

          The nl2br() function will replace all newline characters in a string with '<br />' tags.
          So all you would have to do is run the input text through that function before using it.

          Comment

          • Dameon99
            New Member
            • Jun 2007
            • 57

            #6
            I have tried using guides from the internet to us nl2br but everything I try comes up with an error like 'data can not be altered in this way'. My code seen above doesnt contain my attempts but just the raw code. what I want is to be able to take the input for one of the variables and convert the \n tags from php to <br> tags in html so that when a customer lists the items they are interested in and the quantity it shows up on seperate lines how they originally formatted it.

            I need for someone to give me very specific unambiguous instructions on how I could implement nl2br in reguards to my code above. Most of the guides online use very obscure examples in code that I would never have the need to use or even understand. I am truly new to php and just need to get the job done. would the code in total be something like:

            $order = nl2br($order); or is there more?

            Comment

            • Dameon99
              New Member
              • Jun 2007
              • 57

              #7
              and also.. does that code go in my html document or my php script?

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                Heya, Dameon.

                Help me out here; I'm a bit confused.

                What would be an example of input that you would need to process?

                Comment

                • jx2
                  New Member
                  • Feb 2007
                  • 228

                  #9
                  if nl2br() is not working properly -
                  you can try str_replace( "\n" , "<br />" ,$yourString)

                  (nl2br dosnt work properly if you use <pre> or textarea - it does not replace \n with <br> it adds <br> after \n)

                  regards
                  jx2

                  Comment

                  • Dameon99
                    New Member
                    • Jun 2007
                    • 57

                    #10
                    Originally posted by jx2
                    if nl2br() is not working properly -
                    you can try str_replace( "\n" , "<br />" ,$yourString)

                    (nl2br dosnt work properly if you use <pre> or textarea - it does not replace \n with <br> it adds <br> after \n)

                    regards
                    jx2
                    Ive tried putting this code in my PHP file but its not working. Is it supposed to go in the PHP or the HTML?

                    Comment

                    • Dameon99
                      New Member
                      • Jun 2007
                      • 57

                      #11
                      Originally posted by Dameon99
                      Ive tried putting this code in my PHP file but its not working. Is it supposed to go in the PHP or the HTML?
                      dw, al good, got it working. Thanks heaps guys x-D

                      Comment

                      • jx2
                        New Member
                        • Feb 2007
                        • 228

                        #12
                        Originally posted by Dameon99
                        dw, al good, got it working. Thanks heaps guys x-D
                        it should work if doesnt we need to see your code

                        regards jx2

                        Comment

                        Working...