[solved] Textarea problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

[solved] Textarea problem

Post by melindaSA »

I have a textarea and when the user enters info into the textarea, they can click anywhere in the box, how do I force the curser to the left. Also when the form is submitted, if there is no info entered into the box, it is submitted with spaces, so mySql shows that it is not null. I have tried stripslashes and trim......Help!!

Here is my code:

Code: Select all

<tr>
    <td>Required:</td>
    <td><textarea rows="5" cols="30"
          name="r_experience">
          <?php echo trim($edit?$positions&#1111;'r_experience']:''); ?>
          </textarea></td>

 </tr>
  <tr>
    <td>Preferred:</td>
    <td><textarea name="p_experience" rows="5" cols="30" wrap="physical">
          <?php echo $edit?$positions&#1111;'p_experience']:''; ?>
          </textarea></td>
  </tr>
?>
Last edited by melindaSA on Mon Feb 16, 2004 12:49 pm, edited 1 time in total.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Just let them type whatever they want in the textarea, spaces/nothing etc.. and trim() the posted var then check if it's empty() or not. E.g.

if(isset($_POST['r_experience'])){
$r_exp = trim($_POST['r_experience']);
if(!empty($r_exp)){
//it's been trimmed and it's not empty, can go in db
} else {
//it's empty so ignore inserting it
}
}
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Try

Code: Select all

<tr>
    <td>Required:</td>
    <td><textarea rows="5" cols="30"
          name="r_experience"><?php echo trim($edit?$positions&#1111;'r_experience']:''); ?></textarea></td>

</tr>
  <tr>
    <td>Preferred:</td>
    <td><textarea name="p_experience" rows="5" cols="30" wrap="physical"><?php echo $edit?$positions&#1111;'p_experience']:''; ?>          </textarea></td></tr>
You had spaces between your <textarea> tags, and that is what was causing the problem.
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

Post by melindaSA »

Thank you, that has fixed it.... :D
Post Reply