JCS1988 Posted May 8, 2009 Share Posted May 8, 2009 I am using an HTML form that posts the data to confirm.php which I created. There the users sees a confirmation screen and the data is mailed out to my email address. All of this works great, except for when the user navigates directly to the confirm.php, skipping over the form page. The form is mailed out with all fields blank. I did get a solution to this problem awhile ago but it no longer works. I'm guessing the newer PHP doesn't support it. What I want is for PHP to check and see if data exists. If no data is present the user should be redirected to index.html, if there is data they will see the confirmation and the email will be sent to me. The first few lines are what originally would check for data and if none was present they would be directed to index.html. I just need something that will provide the same function as this one did before. Thanks! <?php if (sizeof($_POST)==0) { header("Location:index.html"); } else { $where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/")); // Checkbox handling $field_14_opts = $_POST['field_14'][0].",". $_POST['field_14'][1].",". $_POST['field_14'][2]; mail("jessesimmers@gmail.com","Website Form","Form data: First Name: " . $_POST['field_1'] . " Last Name: " . $_POST['field_2'] . " Address: " . $_POST['field_3'] . " City: " . $_POST['field_4'] . " State: " . $_POST['field_5'] . " Zip Code: " . $_POST['field_6'] . " Home Phone: " . $_POST['field_7'] . " Cell Phone: " . $_POST['field_8'] . " Email: " . $_POST['field_9'] . " Best Time To Reach You: " . $_POST['field_10'] . " Best Day To Reach You: " . $_POST['field_11'] . " Number of Windows: " . $_POST['field_12'] . " I Am Interested In: $field_14_opts "); ?> Quote Link to comment Share on other sites More sharing options...
allworknoplay Posted May 8, 2009 Share Posted May 8, 2009 if (isset($_POST)) { header("Location:index.html"); } else Quote Link to comment Share on other sites More sharing options...
SharkBait Posted May 8, 2009 Share Posted May 8, 2009 Technically if they submit a form $_POST will always have at least the submit value set. Because it is set like an array you could try something like: <?php if(isset($_POST) && count($_POST) > 1) { //do stuff // form was submitted } else { //do something else // form submitted but no values were set } ?> So the $_POST variable has to have at least 2 or more values. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 if (isset($_POST)) { header("Location:index.html"); } else By the way, $_POST is *always* set. Unless someone unsets it. Quote Link to comment Share on other sites More sharing options...
allworknoplay Posted May 8, 2009 Share Posted May 8, 2009 if (isset($_POST)) { header("Location:index.html"); } else By the way, $_POST is *always* set. Unless someone unsets it. Is that right? You learn something new everyday.. I normally don't use POST as a way to check, I normally check for a SESSION to exist. But for POST, if he wants to double double make sure, he can include a hidden type say: myform and set the value to true when they hit submit. Then on the confirm page, he can check to see if $_POST['myform'] == true But that's kind of a hack way to do things... He should really invest in sessions.... Quote Link to comment Share on other sites More sharing options...
juma929 Posted May 9, 2009 Share Posted May 9, 2009 Hey, from your example, id just check to make sure the submit button has been pressed, so if you have a submit button with the name of "go", do this: if(isset($_POST['go'])) { // They have pressed submit. } else { // Somebody is cheating... header("Location: index.html"); exit(); // for that warm feel good security feeling. } Thanks, Justin Quote Link to comment Share on other sites More sharing options...
jackpf Posted May 9, 2009 Share Posted May 9, 2009 if($_SERVER['REQUEST_METHOD'] != 'POST') Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted May 9, 2009 Share Posted May 9, 2009 Hey, from your example, id just check to make sure the submit button has been pressed, so if you have a submit button with the name of "go", do this: if(isset($_POST['go'])) { // They have pressed submit. } else { // Somebody is cheating... header("Location: index.html"); exit(); // for that warm feel good security feeling. } Thanks, Justin Baaaad idea. Some browsers wont send the submit button unless it's actually been clicked. So all those people who press enter to submit the form will be confused. And ken is right - $_POST is always set. Just check it's size with count. Quote Link to comment Share on other sites More sharing options...
jackpf Posted May 9, 2009 Share Posted May 9, 2009 Some browsers wont send the submit button unless it's actually been clicked. No, IE won't send the submit button unless it's been clicked Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.