Jump to content

[SOLVED] form issue


cha0sriderx

Recommended Posts

i was wondering when make a form with a text area how do u make it show the breaks?

 

like if u have this is a textarea:

abc

def

 

normally is shows up as:

abc def

 

how do u make it show up how it is in the textarea?

 

this is what i have:

contact.php

<form action="send.php?form=contact" method="post">
<table class=form align=center>
<tr>
   <td align=right valign=bottom>
     Name:
   </td>
   <td>
     <input type="text" name="name" size="35">
   </td>
  </tr>
  <tr>
    <td align=right valign=bottom>
      Email:
    </td>
    <td>
      <input type="text" name="email" size="35">
    </td>
  </tr>
  <tr>
    <td align=right valign=top>
      Message:
    </td>
    <td>
      <textarea name="comment" rows="8" cols="35"></textarea>
    </td>
  </tr>
  <tr>
    <td align=center>
    </td>
    <td align=right>
      <input type="submit" value="Send Form"> <input type="reset" value="Reset">
    </td>
  </tr>
</table>
</form>

 

send.php

<?
$form = $_GET['form'];
if ($form == contact) { 

  $n = $_POST['name'];
  $e = $_POST['email'];
  $c = $_POST['comment'];

  if ((empty($n)) || (empty($e)) || (empty($c))) {
     echo "<center>Please fill out the form completely.<br><a href='contact.php'>back</a></center>";
     exit();
  }

  echo "$n ($e)<br>$c";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/63248-solved-form-issue/
Share on other sites

Basically, HTML uses <br /> while the textarea uses \n. When for ex u enter some text from a textarea in a database, retrieving that data from the db u would have smth like 'text\ntext\ntext'. To convert all the newlines in html brakes u can use the nl2br function. Pretty easy:

 

echo nl2br('this is some\ntext');

Link to comment
https://forums.phpfreaks.com/topic/63248-solved-form-issue/#findComment-315287
Share on other sites

Archived

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

×
×
  • Create New...

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.