Two, if all the fields are correctly filled out, I would like to have a page that has all the mySQL inserting. I thought I could just use include() and all the variables would be magically passed to it, but no. What is a possibility of doing this?
Checking form in PHP_SELF, then including the upload
Moderator: General Moderators
Checking form in PHP_SELF, then including the upload
Sooooo... yea. 2 problems. One, when I use $_SERVER['PHP_SELF'] for the form action, and it is submitted, the fields go blank. I would like them to stay put, so if there is an error, then the user can fix it without having to fill it ALL back in.
Two, if all the fields are correctly filled out, I would like to have a page that has all the mySQL inserting. I thought I could just use include() and all the variables would be magically passed to it, but no. What is a possibility of doing this?

Two, if all the fields are correctly filled out, I would like to have a page that has all the mySQL inserting. I thought I could just use include() and all the variables would be magically passed to it, but no. What is a possibility of doing this?
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
ok here goes:
Hope that makes sense. So when its run you get the form shown as $_POST[submit] is false. You then post the form and $_POST[submit] is true so it runs the next part.
If all the data is good - filled in, not fake emails etc - then you can submit the data to the database. If there is a problem, then you show an error message and a submit button - with a lot of hidden fields with the rest of the data in - then that sets $_POST[submit] to false - so the form is shown, but since there are $_POST[] values, these are put as the default value in the form.
Code: Select all
if(!$_POST[submit]){ //the form hasnt been submitted - so show it
//put your form here and you MUST call your submit button "submit" and set it to a value of 1, or create a hidden field called submit.
//example of what the fields should look like
echo "<input type="text" name="test" value="$_POST[test]">";
//this will then place the value back in the field if we have to come back to the form
}else{
//the form has been submitted so do some checks on the data
if($all_the_data_is_good){
//...mysql_query(); stuff
}else{
//create another form - submit to the samepage, but make "submit" = 0 so that it will show the original form again. Then place all data you got from the form into hidden fields so its passed back to the original form. Display some error message.
}
}If all the data is good - filled in, not fake emails etc - then you can submit the data to the database. If there is a problem, then you show an error message and a submit button - with a lot of hidden fields with the rest of the data in - then that sets $_POST[submit] to false - so the form is shown, but since there are $_POST[] values, these are put as the default value in the form.
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
yea but on first opening through he'll get errors because the $_POST vars aren't set - instead do
Code: Select all
<input type="text" name="test" <?if(isset($_POST[test])) echo "value="$_POST[test]""; ?>>-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK