Forum Moderators: coopster

Message Too Old, No Replies

refreshing blank page

         

marker5a

7:25 pm on Jul 7, 2004 (gmt 0)

10+ Year Member



Ok
the follwoing script is a simple form that I am using. I want the form to go to the same script using "?true=submission". When it submits, i want it to display "blah", but instead, it displays the form again, and than following it is blah. What to do? thanks

Chris

<?php
$true=$HTTP_GET_VARS['true'];

if($true==0){
#Generate initial prompting form
$month=date("n");$day=date("j");$year=date("y");$date="$month/$day/$year";
print " <form method=\"POST\" action=\"$PHP_SELF?true=submission\">

<p style=\"word-spacing: 0; line-height: 100%; margin-top: 0; margin-bottom: 0\">Date:&nbsp; <input type=\"text\" name=\"date\" size=\"20\" value=\"$date\"></p>

<p style=\"word-spacing: 0; line-height: 100%; margin-top: 0; margin-bottom: 0\"><input type=\"text\" name=\"miles\" size=\"20\" value=\"Enter Miles\"></p>

<p style=\"word-spacing: 0; line-height: 100%; margin-top: 0; margin-bottom: 0\"><input type=\"text\" name=\"location\" size=\"20\" value=\"Enter Location\"></p>

<p style=\"word-spacing: 0; line-height: 100%; margin-top: 0; margin-bottom: 0\"><select size=\"1\" name=\"time\">
<option selected>AM</option>
<option>Noon</option>
<option>PM</option>
</select></p>

<p style=\"word-spacing: 0; line-height: 100%; margin-top: 0; margin-bottom: 0\"><textarea rows=\"4\" name=\"comments\" cols=\"20\">Enter Comments</textarea><input type=\"submit\" value=\"Submit\" name=\"B1\"><input type=\"reset\" value=\"Reset\" name=\"B2\"></p>
</form>\n ";}
if($true==submission){echo 'blah';}
?>

rlkanter

8:24 pm on Jul 7, 2004 (gmt 0)

10+ Year Member



I'm not sure I entirely understand, first you should be checking that B1 value at the beginning I think.

if(!$_POST['B1'] ){
/* form code here */
} else {
echo 'blah';
}

If you want to actually have it load a page where?true=submission is appended to the end of your current script you'd probably have to add something similar to:

if(!$_POST['B1'] &&!$_GET['true'] ){
/* form code here */
} else {
if( $_GET['true'] ){
$loc = $_SERVER['PHP_SELF'] . "?true=submission";
header( "Location: $loc" );
}
}

Birdman

9:13 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Adding a GET variable to the form action will work, but I agree with rlkanter. You don't need it. Just check for any of the POST vars in your form, if they are set, then you know it was submitted.

httpwebwitch

4:21 pm on Jul 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I prefer to put the submission trigger in the form itself, as a hidden <input>. That way, the script detects a submission, even if the form is submitted completely blank. Nice for validation.

Here is a sample of how it can be used:


<?php
$errors=array();
if ($_POST['action']=='process'){
// validate
if (strlen($_POST['myvar'])<1){
$errors['myvar']="<b>myvar isn't set!</b><BR>";
}
// etc
}

if (count($errors)==0){
// process the form
}else{
// show the form again, with errors indicated
?>
<form action="<?php print($PHP_SELF)?>" method="POST">
<input type="hidden" name="action" value="process">
<?php print($errors['myvar'])?>
<input type="text" name="myvar" value="<?php print($_POST['myvar'])?>">
<input type="submit">
</form>
<?php
}
?>

The same method is good for multi-part forms, where you can set action='step1' or action='step2'

marker5a

4:38 pm on Jul 8, 2004 (gmt 0)

10+ Year Member



wow, thanks for the help guys, got it rolling now. Thanks again

Chris