Page 1 of 1
php form
Posted: Thu Aug 03, 2006 5:12 pm
by eektech909
i have a php form that adds info to a sql table to dynamically load on a website.
when they click submit it runs a PHP_SELF to reload the page and validates the form for blank boxes,etc...
how can i set it up so when it finds the error it keeps the current information in the text boxes rather than clearing them out
Posted: Thu Aug 03, 2006 5:31 pm
by Luke
store the values of each form into a variable and then print the variable into value on the page:
Validation script
Code: Select all
<?php
$title = some_type_of_filter($_POST['title']);
?>
<input type="text" name="title" value="<?php echo $title; ?>" />
Does that make sense?
Posted: Thu Aug 03, 2006 7:21 pm
by s.dot
Well, if your page is reloading when there's an error, and you're not SUBMITTING any data for PROCESSING yet.. but just offering the form to the user again, something along the lines of this would be perfect:
Code: Select all
<input type="text" name="myTextField" size="20"<?php
if(!empty($_POST['myTextField'])){
echo ' value="'.htmlentities($_POST['myTextField'],ENT_QUOTES).'"';
}
?>>
Posted: Mon Aug 07, 2006 6:10 pm
by eektech909
how do i get the value of the text boxes to go blank after the correct info has been submitted?
Posted: Mon Aug 07, 2006 7:35 pm
by RobertGonzalez
You remove the form from the equation. On first load, show the form. On submit, check the passed data. If it validates, process the data and show a success message, not the form. If the data does not validate, show an error message AND the form.