473,385 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Replace form inputs with <br> tags

HI, Im new to PHP completely but Im wanting to format the inputs for $order and $specialinstructions 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?!

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // multiple recipients
  4. $newcustomer = $_POST["newcustomer"];
  5. $name = $_POST["name"];
  6. $accountnumber = $_POST["accountnumber"];
  7. $deliveryaddress = $_POST["deliveryaddress"];
  8. $nameoforderer = $_POST["nameoforderer"];
  9. $phone = $_POST["phone"];
  10. $email = $_POST["email"];
  11. $deliverydate = $_POST["deliverydate"];
  12. $deliverytime = $_POST["deliverytime"];
  13. $order = $_POST["order"];
  14. $specialinstructions = $_POST["specialinstructions"];
  15. $billing = $_POST["billing"];
  16.  
  17. // multiple recipients
  18. $to = 'andrew@domain.com';
  19. //$to = 'you@domain.com.au' . ', '; // note the comma
  20. //$to .= 'wez@example.com';
  21.  
  22. // subject
  23. $subject = 'your_domain Website Order';
  24.  
  25. // message
  26. $message = '
  27. <html>
  28. <head>
  29. <title>your_domain Website Order</title>
  30. </head>
  31. <body>
  32. <table width=450 border=0 cellspacing=6 cellpadding=0>
  33. <tr>
  34. <td WIDTH=182>&nbsp;</td>
  35. <td WIDTH=268>
  36. <center>
  37. <h3 ALIGN=LEFT>your_domain Website Order</h3>
  38. </center>
  39. </td>
  40. </tr>
  41. <tr>
  42. <td WIDTH=182>
  43. <p ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>New Customer:</font></p>
  44. </td>
  45. <td WIDTH=268>
  46. <div ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>
  47. <strong>'.$newcustomer.'</strong></font></div>
  48. </td>
  49. </tr>
  50. <tr>
  51. <td WIDTH=182>
  52. <p ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>Customer Account Name:</font></p>
  53. </td>
  54. <td WIDTH=268>
  55. <div ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>
  56. <strong>'.$name.'</strong></font></div>
  57. </td>
  58. </tr>
  59. <tr>
  60. <td WIDTH=182>
  61. <p ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>Account Number:</font></p>
  62. </td>
  63. <td WIDTH=268>
  64. <div ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>
  65. <strong>'.$accountnumber.'</strong> </font></div>
  66. </td>
  67. </tr>
  68. <tr>
  69. <td WIDTH=182>
  70. <p ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>Delivery Address:</font></p>
  71. </td>
  72. <td WIDTH=268>
  73. <div ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>
  74. <strong>'.$deliveryaddress.'</strong> </font></div>
  75. </td>
  76. </tr>
  77. <tr>
  78. <td WIDTH=182>
  79. <p ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>Name of Person Ordering:</font></p>
  80. </td>
  81. <td WIDTH=268>
  82. <div ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>
  83. <strong>'.$nameoforderer.'</strong> </font></div>
  84. </td>
  85. </tr>
  86. <tr>
  87. <td WIDTH=182>
  88. <p ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>Phone:</font></p>
  89. </td>
  90. <td WIDTH=268>
  91. <div ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>
  92. <strong>'.$phone.'</strong> </font></div>
  93. </td>
  94. </tr>
  95. <tr>
  96. <td WIDTH=182>
  97. <p ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>Email:<br>
  98. </font></p>
  99. </td>
  100. <td WIDTH=268>
  101. <div ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>
  102. <strong>'.$email.'</strong> </font></div>
  103. </td>
  104. </tr>
  105. <tr>
  106. <td WIDTH=182>
  107. <p ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>Delivery Date:<br>
  108. </font></p>
  109. </td>
  110. <td WIDTH=268>
  111. <div ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>
  112. <strong>'.$deliverydate.'</strong> </font></div>
  113. </td>
  114. </tr>
  115. <tr>
  116. <td WIDTH=182> <font FACE=Arial, Helvetica, sans-serif SIZE=2>Delivery Time:<br>
  117. </font></td>
  118. <td WIDTH=268>
  119. <div ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>
  120. <strong>'.$deliverytime.'</strong> </font></div>
  121. </td>
  122. </tr>
  123. <tr>
  124. <td WIDTH=182 valign="top">
  125.  
  126. <p ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>Order:<br>
  127. </font></p>
  128. </td>
  129. <td WIDTH=268>
  130. <div ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>
  131. <strong>'.$order.'</strong> </font></div>
  132. </td>
  133. </tr>
  134. <tr>
  135. <td WIDTH=182>
  136.  
  137. <p ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>Special Instructions:<br>
  138. </font></p>
  139. </td>
  140. <td WIDTH=268>
  141. <div ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>
  142. <strong>'.$specialinstructions.'</strong> </font></div>
  143. </td>
  144. </tr>
  145.  
  146. <tr>
  147. <td WIDTH=182>
  148.  
  149. <p ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>Billing:<br>
  150. </font></p>
  151. </td>
  152. <td WIDTH=268>
  153. <div ALIGN=LEFT><font FACE=Arial, Helvetica, sans-serif SIZE=2>
  154. <strong>'.$billing.'</strong> </font></div>
  155. </td>
  156. </tr>
  157.  
  158. </table>
  159.  
  160.  
  161.  
  162. </body>
  163. </html>
  164. ';
  165.  
  166. // To send HTML mail, the Content-type header must be set
  167. $headers = 'MIME-Version: 1.0' . "\r\n";
  168. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  169.  
  170. // Additional headers
  171.  
  172. $headers .= 'From: your_domain Website <info@your_domain.com.au>' . "\r\n";
  173.  
  174. // Mail it
  175. mail($to, $subject, $message, $headers);
  176. header("Location: http://www.your_domain.com.au/thankyou.html");
  177. ?>
Aug 13 '07 #1
11 1897
ak1dnar
1,584 Expert 1GB
Thread Title *Help!!!* Replaced.
What makes a Good Thread Title
Aug 13 '07 #2
Thanks.. I think.. I really just need help with my code.
Aug 13 '07 #3
pbmods
5,821 Expert 4TB
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.
Aug 13 '07 #4
Atli
5,058 Expert 4TB
HI, Im new to PHP completely but Im wanting to format the inputs for $order and $specialinstructions 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.
Aug 13 '07 #5
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?
Aug 14 '07 #6
and also.. does that code go in my html document or my php script?
Aug 14 '07 #7
pbmods
5,821 Expert 4TB
Heya, Dameon.

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

What would be an example of input that you would need to process?
Aug 14 '07 #8
jx2
228 100+
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
Aug 14 '07 #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
Ive tried putting this code in my PHP file but its not working. Is it supposed to go in the PHP or the HTML?
Aug 19 '07 #10
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
Aug 19 '07 #11
jx2
228 100+
dw, al good, got it working. Thanks heaps guys x-D
it should work if doesnt we need to see your code

regards jx2
Aug 19 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: fis | last post by:
Hi all, I've problem because there are needed break lines in my texts on the web site but i can't do it :( My pipeline looks like: XMS -> I18N -> XSLT -> HTML I have lot of texts in my...
6
by: Lasse | last post by:
I have done this simple function, it seems to work as intended, to solve a problem i have had for a while. I couldnt find any sample around that was working for me. I would like to test it with...
25
by: Shannon Jacobs | last post by:
Maybe there is a simple trick here, and I'm not spotting it... Is there a guru of CSS hanging around here who can help out? The page in question has a multi-column table with a list of links in...
0
by: CoreyMas | last post by:
Hello everyone, I am in a bit of a dilema trying to write an HTML <br> tag into a panel or placeholder. Here is the situation I have 4 tables that represent 4 levels of data (level4 is...
15
by: tshad | last post by:
How do I go about this? I used to know this, but can't find VB.net replace that does this. Something like string.replace("<br>",NL) Thanks,
1
by: mmahon512 | last post by:
This works for some of my site. But I have some records that are already marked up as HTML so I am getting extra <br> tags when certain records are marked up with HTML and others are just straight...
4
by: Christofer Dutz | last post by:
Hi, I am having a small problem, that is driving me nuts. My application reads some Xml and runs 2 Xsl Transformations to generate HTML. As soon as my second XSL introduces some <br/tags, the...
11
cheezylu
by: cheezylu | last post by:
I'm working on a site where my client will be able to maintain some of the text on the site using input boxes and such driven by PHP and MySQL. The problem I am running into is making it easy for...
8
by: Sven | last post by:
Dear all, I'm trying to extract data from HTML using XPath in Java. Unfortunately the text contents of nodes may contain <br/tags which are not correctly interpreted, at least not for me ;) A...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.