Stop PHP form inputs returning empty after validation


/ Published in: PHP
Save to your folder(s)

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!


Copy this code and paste it in your HTML
  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>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.