Jump to content


Photo

Problem with form.. using echo statement


  • Please log in to reply
6 replies to this topic

#1 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 12 July 2006 - 12:46 AM

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.

$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']))

That's the easy part. Just recalling the variables from the form that was on another page.

<?php echo "$Customer"?><br>
        <?php echo "$Address"?><br>
        <?php echo "$Contact"?> - <?php echo "$CPhone"?>

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!

#2 Chevy

Chevy
  • Members
  • PipPipPip
  • Advanced Member
  • 163 posts

Posted 12 July 2006 - 01:02 AM

<?php echo "$Customer";?><br>
        <?php echo "$Address";?><br>
        <?php echo "$Contact";?> - <?php echo "$CPhone";?>

See if that works

If you are subbmiting the form try something like
<?php
if ($_POST['submit']){ 
echo "$Customer
<br>
$Address
<br>
$Contact - $CPhone";
}
?>


Just a suggestion

#3 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 12 July 2006 - 01:15 AM

Hm.. tried out both of those with no avail. Thanks for the reply, though!

#4 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 12 July 2006 - 01:29 AM

Have you try putting isset ?

if (isset($_POST['submit'])) {
<?php echo "$Customer"?><br>
        <?php echo "$Address"?><br>
        <?php echo "$Contact"?> - <?php echo "$CPhone"?>
} else {
// show the form here
}


Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#5 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 12 July 2006 - 05:18 PM

Look function nl2br()

#6 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 12 July 2006 - 05:33 PM

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).
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#7 SephirGaine

SephirGaine
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 12 July 2006 - 07:31 PM

Awesome, the nl2br function worked flawlessly. Thanks a lot for the help!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users