Jump to content


This topic is now archived and is closed to further replies.


Problem with form.. using echo statement

Recommended Posts

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!

Share this post

Link to post
Share on other sites
[code]<?php echo "$Customer";?><br>
        <?php echo "$Address";?><br>
        <?php echo "$Contact";?> - <?php echo "$CPhone";?>[/code]

See if that works

If you are subbmiting the form try something like
if ($_POST['submit']){
echo "$Customer
$Contact - $CPhone";


Just a suggestion

Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites
Look function nl2br()

Share this post

Link to post
Share on other sites
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).

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.