Jump to content

Need to launch a "thank you" page after submitting PHP form


NBRAD

Recommended Posts

<?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'";
}
?>

Link to comment
Share on other sites

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.');

}

 

 

}

 

 

?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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.');
}


}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

<?

 

 

 

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.');

  }

 

}

 

?>

 

 

 

 

Link to comment
Share on other sites

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.');
    }
}

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.