NBRAD Posted May 8, 2008 Share Posted May 8, 2008 If I post script here for a PHP feedback form, can someone tell me how to program the launch of a "thank you" page, once the user has successfully submitted the form? I'm very new to this. Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/ Share on other sites More sharing options...
947740 Posted May 8, 2008 Share Posted May 8, 2008 Change the location of the page. header("Location: thankyou.html"); *Note You cannot echo information or anything before using the header(); statement. Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-535888 Share on other sites More sharing options...
Fadion Posted May 8, 2008 Share Posted May 8, 2008 <?php if(isset($_POST['text'])){ //if the form is submitted header('Location: thanks.php'); //or use meta refresh, so u dont care about already sent headers //echo "<meta http-equiv='refresh' content='0;thanks.php'"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-535901 Share on other sites More sharing options...
BlueSkyIS Posted May 8, 2008 Share Posted May 8, 2008 (i personally never use meta refresh since it can be ignored.) Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-535902 Share on other sites More sharing options...
NBRAD Posted May 8, 2008 Author Share Posted May 8, 2008 I'm REALLY new to this. I don't quite understand where to post the code, header("Location: thankyou.html"); Nor do I know exactly which part is the code and which is just descriptive information (i.e., is "header" part of the code?) Again, this is all very new to me.. Here is the code I'm using that is telling the form to submit. Can you give me a little more instruction? Thank you. <? if($submit) { $body = "You may contact $name for information and/or future mailings. \n\n"; $body .= "Name: $name\n"; $body .= "Email: $submitBy\n"; $body .= "Gender: $gender\n"; $body .= "Age: $age\n"; $body .= "Organization: $organization\n"; $body .= "Title: $title\n\n"; $body .= "Address: $address1\n"; $body .= "Address: $address2\n"; $body .= "City: $city\n"; $body .= "State: $state\n"; $body .= "Zip Code: $zip\n"; $body .= "Country: $country\n\n"; $body .= "Series Listed To: $series1,$series1, $series2, $series3, $series4, $series5,\n\n"; $body .= "Plans to use the website for: $website_use\n\n"; $body .= "Heard about website from: $referal\n\n"; $body .= "Suggestions: $suggestions\n\n"; $body .= "Comments: $comments\n\n"; $fromEmail = "From: $submitBy"; /* print("Your Email: " . $adminEmail . "<br>"); print("Subject: ". $subject . "<br>"); print("Body: " . $body . "<br>"); print("From Email: " . $fromEmail . "<br>"); */ if(mail($adminEmail, $subject, $body, $fromEmail)) { ?> <p><br /> <p></p> <? } else { echo('Send Mail Failed please try again or contact administrator to fix the error.'); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-535965 Share on other sites More sharing options...
Fadion Posted May 8, 2008 Share Posted May 8, 2008 I suppose u need to redirect here: <?php if(mail($adminEmail, $subject, $body, $fromEmail)){ echo "<meta http-equiv='refresh' content='0;thanks.php'"; //<< here } else{ echo 'Send Mail Failed please try again or contact administrator to fix the error.'; } ?> I used meta refresh as uve already sent the headers by printing out some values. If u want to use a pure php approach, then look at functions like ob_start() and such, but guess it would be too complicated for u. Stick to meta refresh for now. Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536000 Share on other sites More sharing options...
NBRAD Posted May 8, 2008 Author Share Posted May 8, 2008 I'm sorry. Could someone explain in complete layperson's terms what code to put where? I am a total beginner and really desperate. Some of these responses are over my head. I know that I need the submit function to launch a new page (which I have already created), I just don't know how to do it. I would really appreciate help. The code I'm using for submit is pasted in my post above. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536012 Share on other sites More sharing options...
Fadion Posted May 8, 2008 Share Posted May 8, 2008 <?php if($submit) { $body = "You may contact $name for information and/or future mailings. \n\n"; $body .= "Name: $name\n"; $body .= "Email: $submitBy\n"; $body .= "Gender: $gender\n"; $body .= "Age: $age\n"; $body .= "Organization: $organization\n"; $body .= "Title: $title\n\n"; $body .= "Address: $address1\n"; $body .= "Address: $address2\n"; $body .= "City: $city\n"; $body .= "State: $state\n"; $body .= "Zip Code: $zip\n"; $body .= "Country: $country\n\n"; $body .= "Series Listed To: $series1,$series1, $series2, $series3, $series4, $series5,\n\n"; $body .= "Plans to use the website for: $website_use\n\n"; $body .= "Heard about website from: $referal\n\n"; $body .= "Suggestions: $suggestions\n\n"; $body .= "Comments: $comments\n\n"; $fromEmail = "From: $submitBy"; /* print("Your Email: " . $adminEmail . " "); print("Subject: ". $subject . " "); print("Body: " . $body . " "); print("From Email: " . $fromEmail . " "); */ if(mail($adminEmail, $subject, $body, $fromEmail)) { echo "<meta http-equiv='refresh' content='0;thanks.php'"; //<< here ?> <p> <p></p> <?php } else { echo('Send Mail Failed please try again or contact administrator to fix the error.'); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536017 Share on other sites More sharing options...
NBRAD Posted May 8, 2008 Author Share Posted May 8, 2008 Thank you, thank you, thank you! I'm very close. Now, when I test it in Mozilla Firefox, it works perfectly; however, in Internet Explorer, it simply clears the form and remains on that page--does not redirect to the "thank you" page. Any thoughts about why it would work in Firefox and not IE? Thank you again. Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536058 Share on other sites More sharing options...
BlueSkyIS Posted May 8, 2008 Share Posted May 8, 2008 as you've found, browsers can ignore meta tags. i suggest that you use PHP's header() function instead. after mail is sent, you could do this: header("location: thanks.php"); exit; Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536063 Share on other sites More sharing options...
NBRAD Posted May 8, 2008 Author Share Posted May 8, 2008 This is really bad, but I don't know what the header function is. Can you describe where this code header("location: thanks.php"); exit; should be placed in the context of my script? Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536074 Share on other sites More sharing options...
BlueSkyIS Posted May 8, 2008 Share Posted May 8, 2008 put that bit of code in place of this: echo "<meta http-equiv='refresh' content='0;thanks.php'"; //<< here Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536076 Share on other sites More sharing options...
NBRAD Posted May 8, 2008 Author Share Posted May 8, 2008 Hmmm. I replaced only echo "<meta http-equiv='refresh' content='0;thanks.php'"; //<< here with header("location: feedbackthankyou.php"); exit; and it now goes back to clearing the form and not redirecting in both browsers. I've also noticed that when I upload the modified file, and it doesn't work, the feedback form file in the URL appears as a string of strange letters and numbers before the file extension, rather than the feedbackform.php--for example: http://www.XXXXXXXXXXXXX.org/TMP2n6llk9bk.php Is this relevant? Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536101 Share on other sites More sharing options...
BlueSkyIS Posted May 8, 2008 Share Posted May 8, 2008 can you post the latest complete code? Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536104 Share on other sites More sharing options...
NBRAD Posted May 8, 2008 Author Share Posted May 8, 2008 <? if($submit) { $body = "You may contact $name for information and/or future mailings. \n\n"; $body .= "Name: $name\n"; $body .= "Email: $submitBy\n"; $body .= "Gender: $gender\n"; $body .= "Age: $age\n"; $body .= "Organization: $organization\n"; $body .= "Title: $title\n\n"; $body .= "Address: $address1\n"; $body .= "Address: $address2\n"; $body .= "City: $city\n"; $body .= "State: $state\n"; $body .= "Zip Code: $zip\n"; $body .= "Country: $country\n\n"; $body .= "Series Listed To: $series1,$series1, $series2, $series3, $series4, $series5,\n\n"; $body .= "Plans to use the website for: $website_use\n\n"; $body .= "Heard about website from: $referal\n\n"; $body .= "Suggestions: $suggestions\n\n"; $body .= "Comments: $comments\n\n"; $fromEmail = "From: $submitBy"; /* print("Your Email: " . $adminEmail . "<br>"); print("Subject: ". $subject . "<br>"); print("Body: " . $body . "<br>"); print("From Email: " . $fromEmail . "<br>"); */ if(mail($adminEmail, $subject, $body, $fromEmail)) { header("location: feedbackthankyou.php"); exit; ?> <p> <p></p> <? } else { echo('Send Mail Failed please try again or contact administrator to fix the error.'); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536110 Share on other sites More sharing options...
BlueSkyIS Posted May 8, 2008 Share Posted May 8, 2008 there is no HTML or anything else before this code or after it? Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536116 Share on other sites More sharing options...
moon 111 Posted May 8, 2008 Share Posted May 8, 2008 Assuming your thank you page is not thankyou.html, you will need to replace that with the page on the line that says echo "<script>document.location='thankyou.html';</script>"; <?php if($submit) { $body = "You may contact $name for information and/or future mailings. \n\n"; $body .= "Name: $name\n"; $body .= "Email: $submitBy\n"; $body .= "Gender: $gender\n"; $body .= "Age: $age\n"; $body .= "Organization: $organization\n"; $body .= "Title: $title\n\n"; $body .= "Address: $address1\n"; $body .= "Address: $address2\n"; $body .= "City: $city\n"; $body .= "State: $state\n"; $body .= "Zip Code: $zip\n"; $body .= "Country: $country\n\n"; $body .= "Series Listed To: $series1,$series1, $series2, $series3, $series4, $series5,\n\n"; $body .= "Plans to use the website for: $website_use\n\n"; $body .= "Heard about website from: $referal\n\n"; $body .= "Suggestions: $suggestions\n\n"; $body .= "Comments: $comments\n\n"; $fromEmail = "From: $submitBy"; if(mail($adminEmail, $subject, $body, $fromEmail)) { echo "<script>document.location='thankyou.html';</script>"; } else { echo('Send Mail Failed please try again or contact administrator to fix the error.'); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536122 Share on other sites More sharing options...
BlueSkyIS Posted May 8, 2008 Share Posted May 8, 2008 again, Javascript like that can be ignored. the best, surest way to send a browser to another page via PHP is to use the header() function. my expectation is that there is some output before header() is used, thus creating a header error that is not being displayed due to errors being turned off or something similar. if i can see the entire code file, the problem should become more apparent. Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536123 Share on other sites More sharing options...
NBRAD Posted May 8, 2008 Author Share Posted May 8, 2008 I replaced my "submit" code with the code from the second to last post (replacing the thankyou.html with my own file name) and it worked! Thank you so much. I have been working on this for so long. This is a great relief. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536142 Share on other sites More sharing options...
947740 Posted May 8, 2008 Share Posted May 8, 2008 again, Javascript like that can be ignored. the best, surest way to send a browser to another page via PHP is to use the header() function. I would seriously take that (^) into consideration. Some browsers have javascript completely turned off, which would completely destroy the purpose of it. I would go with headers. Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536152 Share on other sites More sharing options...
Fadion Posted May 9, 2008 Share Posted May 9, 2008 The javascript is completely out of place, ppl are being sceptic here even on meta refresh. Using header() is the best way, but for someone who can barely understand the code he wrote (or not), errors like "headers already sent" will just make his life worse. I'd stick to meta refresh. Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536481 Share on other sites More sharing options...
Daniel0 Posted May 9, 2008 Share Posted May 9, 2008 as you've found, browsers can ignore meta tags. i suggest that you use PHP's header() function instead. after mail is sent, you could do this: again, Javascript like that can be ignored. the best, surest way to send a browser to another page via PHP is to use the header() function. So can the Location and Refresh headers. You cannot force the user to do anything at all. As in real life, just because you tell people to do something, it doesn't mean they will do it. Quote Link to comment https://forums.phpfreaks.com/topic/104705-need-to-launch-a-thank-you-page-after-submitting-php-form/#findComment-536519 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.