Posted By

montanaflynn on 06/18/09


Tagged

form valid input empty validation echo textarea isset


Versions (?)

Stop PHP form inputs returning empty after validation


 / Published in: PHP
 

URL: http://www.complimedia.com/contact.php

This is a short and sweet snippet that will save the users form input after PHP runs validation and returns false. Very good for User Experience!

  1. <?php if(isset($_POST['FORM_INPUT_OR_TEXTAREA_NAME_GOES_HERE'])){ echo $_POST['FORM_INPUT_OR_TEXTAREA_NAME_GOES_HERE']; } ?>
  2.  
  3. SAMPLE OF A FORM INPUT:
  4.  
  5. <input name="name" size="20" value="<?php if(isset($_POST['name'])){ echo $_POST['name']; } ?>">
  6.  
  7. SAMPLE OF A FORM TEXTAREA:
  8.  
  9. <textarea name="comments" rows=5 cols=20><?php if(isset($_POST['comments'])){ echo $_POST['comments']; } ?></textarea>

Report this snippet  

You need to login to post a comment.