SephirGaine Posted July 12, 2006 Share Posted July 12, 2006 Hey ya'll. Before laying out the code, here's my problem in written form. I'm creating a form that generates a work order request form. I have two textareas that need to stay that way (Address, Description) but when I put a line break into the textarea (from the user's point, not coding) all the text I enter remains on a single line when I run the script and generate the form.So, without further ado, here's my coding thus far. I'll be the first to admit that I'm a complete noob when it comes to PHP, but this project just kind of fell on my lap all of a sudden, so I'd had to learn real fast.[code]$Customer = Trim(stripslashes($_POST['Customer']));$Description = Trim(stripslashes($_POST['Description']));$Contact = Trim(stripslashes($_POST['Contact']));$CPhone = Trim(stripslashes($_POST['CPhone']));$Address = Trim(stripslashes($_POST['Address']))[/code]That's the easy part. Just recalling the variables from the form that was on another page.[code]<?php echo "$Customer"?><br> <?php echo "$Address"?><br> <?php echo "$Contact"?> - <?php echo "$CPhone"?>[/code]And there's the other part. I've got another echo statement below for the description, however it's formatted the same way. The Address part is where I'm having trouble creating the user-entered line breaks. So I'm wondering what I need to add to this to make it work.The thing that really confuses me is that I also have a contact form that submits an email on another part of the website, and when I enter line breaks into THAT, they show up perfectly fine in the email. However, 99% chance that the change of formats is key there. I'd appreciate any help I can get, and thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/14344-problem-with-form-using-echo-statement/ Share on other sites More sharing options...
Chevy Posted July 12, 2006 Share Posted July 12, 2006 [code]<?php echo "$Customer";?><br> <?php echo "$Address";?><br> <?php echo "$Contact";?> - <?php echo "$CPhone";?>[/code]See if that worksIf you are subbmiting the form try something like[code]<?phpif ($_POST['submit']){ echo "$Customer<br>$Address<br>$Contact - $CPhone";}?>[/code]Just a suggestion Quote Link to comment https://forums.phpfreaks.com/topic/14344-problem-with-form-using-echo-statement/#findComment-56552 Share on other sites More sharing options...
SephirGaine Posted July 12, 2006 Author Share Posted July 12, 2006 Hm.. tried out both of those with no avail. Thanks for the reply, though! Quote Link to comment https://forums.phpfreaks.com/topic/14344-problem-with-form-using-echo-statement/#findComment-56558 Share on other sites More sharing options...
hackerkts Posted July 12, 2006 Share Posted July 12, 2006 Have you try putting [b]isset[/b] ?[code]if (isset($_POST['submit'])) {<?php echo "$Customer"?><br> <?php echo "$Address"?><br> <?php echo "$Contact"?> - <?php echo "$CPhone"?>} else {// show the form here}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14344-problem-with-form-using-echo-statement/#findComment-56560 Share on other sites More sharing options...
sasa Posted July 12, 2006 Share Posted July 12, 2006 Look function nl2br() Quote Link to comment https://forums.phpfreaks.com/topic/14344-problem-with-form-using-echo-statement/#findComment-56844 Share on other sites More sharing options...
Buyocat Posted July 12, 2006 Share Posted July 12, 2006 nl2br sounds like what you want... It converts carriages (line breaks) in the submitted text to <br />. That way if the user hits enter he sees that in the display. Of course if he is editing it he will also see the <br />. So to avoid that you might try eregi_replace() and look for <br /> and replace it with "\n" (the symbol for new line in PHP). Another approach would be to run the text through nl2br only when printed for display and when printed for editing just dump it as the user submitted it (with carriages). Quote Link to comment https://forums.phpfreaks.com/topic/14344-problem-with-form-using-echo-statement/#findComment-56849 Share on other sites More sharing options...
SephirGaine Posted July 12, 2006 Author Share Posted July 12, 2006 Awesome, the nl2br function worked flawlessly. Thanks a lot for the help! Quote Link to comment https://forums.phpfreaks.com/topic/14344-problem-with-form-using-echo-statement/#findComment-56910 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.