On Sun, Jan 10, 2010 at 11:37:06PM -0600, aditya shukla wrote:
> Hello Guys,
>
> I am trying to validate a form for user input , such that when something is
> missing load the form again by focusing on the wrong field.Say i don not
> enter my address so when the form loads everything else is saved and the
> form points to address field.
Typically, you would direct the form back to itself. Then at the top of
the form, you'd put a test to determine if the form has been processed
before or if this is the first time through. Then you make your decision
about missed fields, etc. Like this:
== someform.php ==
<?php
if (empty($_POST)) {
load_some_values_or_not();
}
else { // form has entered data
$okay = process_for_errors();
if ($okay) {
store_the_data();
header("Location: success.php");
exit();
}
}
?>
HTML crap goes here...
== end of someform.php ==
You'll notice that if there are entry errors, execution falls through.
In that case, you'll need to do something like this for fields:
<input type="text" name="pizza" value="<?php echo $_POST['pizza']; ?>"/>
so that the entered data shows up in the fields. First time through, the
value attribute will yield nothing.
Paul
--
Paul M. Foster
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php