« Multidimensional Arrays || Javascript Expand/Collapse Element »

Use Sticky Forms!

0


If a user inputs information that generates an error OR if he/she leaves a field blank, save them time (and increase your turnover) by using sticky forms. It's so simple and improves usability so much...

Let's say we're collecting first and last names (to keep it simple):

 
form.php
<?php
if (isset($_POST['submitted'])) {
 
		// Print the results.
		echo '
<h1>Your Name:</h1>
 
First: ' . $_POST['first'] . ' Last: ' . $_POST['last'] . '
 
';
 
	} else { // Invalid submitted values.
		echo '
<h1>Error!</h1>
 
Please enter a valid name.
 
';
	}
?>
<h2>Your Name</h2>
<form action="form.php" method="post">
 
First:
<input type="text" name="first" size="30" maxlength="40" value="<?php if (isset($_POST['first'])) echo $_POST['first']; ?>" />
 
Last:
<input type="text" name="last" size="30" maxlength="40" value="<?php if (isset($_POST['last'])) echo $_POST['last']; ?>" />
<input type="submit" name="submit" value="Submit!" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
 

So, if a user inputs a first name but no last name (or last but no first), it will show whatever the user has already typed (and preventing them from having to type it again)...if the form is lengthy, this is very handy and such a time saver.


This entry was posted on Saturday, March 22nd, 2008 at 2:50 pm and is filed under Blog, PHP, WebDev. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Get a Trackback link

No Comments Yet

You can be the first to comment!

Leave a comment