Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP form action is redirecting to wrong page
    primarykey
    data
    text
    <p>I'm currently creating a PHP mail form for a website. The file is called "contactus.php". I need the page to be redirected to "thankyou.php", upon clicking the 'submit' button at the end of the form.</p> <p>Currently it just takes me to a page called "contactus.php/contactus.php", and is completely blank save for the message, "Email sent successfully." </p> <p>I see where it says "Email sent successfully" in the code work, but I'm confused how to change that, and how to change the form action in general, so that the email will still send, but the page will be directed instead to the page "thankyou.php", that I have created. I've tried just simply replacing the form action with "'thankyou.php'", but while it directed the page to "thankyou.php", the email no longer sent.</p> <p>Here is the PHP at the top of the page:</p> <pre><code>&lt;?php require_once("./include/fgcontactform.php"); $formproc = new FGContactForm(); // config $emailAddresses = array( ''=&gt;'', 'Service Department'=&gt;'fakeemail1.com', 'Sales Department'=&gt;'fakeemail2.com', 'Parts Department'=&gt;'fakeemail3.com', 'Customer Service Department'=&gt;'fakeemail4.com', 'Bids Department'=&gt;'fakeemail5.com' // etc etc ); $emailSubject = 'Submitted from Online Form'; // If we are dealing with a form submission, send an email if (isset($_POST['name'])) { // Check the email selected is valid if (!isset($emailAddresses[$_POST['destemail']])) { exit("Sorry, you have selected an invalid email option."); } // Create the body of the email message $emailBody = "Dear {$_POST['destemail']}, \n\n {$_POST['message']} \n\n From: {$_POST['name']} \n Company: {$_POST['company']} \n Phone Number: {$_POST['phone']} \n E-mail: {$_POST['email']} \n Preferred method of contact: {$_POST['method']} \n\n Submitted from Online 'Contact Us' Form"; // Send the email and report the result if (mail($emailAddresses[$_POST['destemail']],$emailSubject,$emailBody,"From: {$_POST['email']}")) {exit("Email sent successfully."); } else {exit("Email sending failed"); } } // Output the html form ?&gt; </code></pre> <p>And here is the form PHP:</p> <pre><code>&lt;?php if(!empty($errors)){ echo "&lt;p class='err'&gt;".nl2br($errors)."&lt;/p&gt;"; } ?&gt; &lt;div id='contact_form_errorloc' class='err'&gt;&lt;/div&gt; &lt;!-- Form Code Start --&gt; &lt;form id='contactus' action='&lt;?php echo $formproc-&gt;GetSelfScript(); echo htmlentities($_SERVER['PHP_SELF']); ?&gt;' method='post' accept-charset='UTF-8'&gt; &lt;fieldset &gt; &lt;input type='hidden' name='submitted' id='submitted' value='1'/&gt; &lt;input type='hidden' name='&lt;?php echo $formproc-&gt;GetFormIDInputName(); ?&gt;' value='&lt;?php echo $formproc-&gt;GetFormIDInputValue(); ?&gt;'/&gt; &lt;div&gt;&lt;span class='error'&gt;&lt;?php echo $formproc-&gt;GetErrorMessage(); ?&gt;&lt;/span&gt;&lt;/div&gt; &lt;div class='container'&gt; &lt;label for='name' &gt;Your Full Name*: &lt;/label&gt;&lt;br/&gt; &lt;input type='text' name='name' id='name' value='&lt;?php echo $formproc- &gt;SafeDisplay('name') ?&gt;' maxlength="50" /&gt;&lt;br/&gt; &lt;span id='contactus_name_errorloc' class='error'&gt;&lt;/span&gt; &lt;/div&gt; &lt;div class='container'&gt; &lt;label for='email' &gt;Email Address*:&lt;/label&gt;&lt;br/&gt; &lt;input type='text' name='email' id='email' value='&lt;?php echo $formproc- &gt;SafeDisplay('email') ?&gt;' maxlength="50" /&gt;&lt;br/&gt; &lt;span id='contactus_email_errorloc' class='error'&gt;&lt;/span&gt; &lt;/div&gt; &lt;div class='container'&gt; &lt;label for='phone' &gt;Phone*:&lt;/label&gt;&lt;br/&gt; &lt;input type='text' name='phone' id='phone' value='&lt;?php echo $formproc- &gt;SafeDisplay('phone') ?&gt;' maxlength="50" /&gt;&lt;br/&gt; &lt;span id='contactus_phone_errorloc' class='error'&gt;&lt;/span&gt; &lt;/div&gt; &lt;div class='container'&gt; &lt;label for='company' &gt;Company Name*:&lt;/label&gt;&lt;br/&gt; &lt;input type='text' name='company' id='company' value='&lt;?php echo $formproc- &gt;SafeDisplay('company') ?&gt;' maxlength="50" /&gt;&lt;br/&gt; &lt;span id='contactus_company_errorloc' class='error'&gt;&lt;/span&gt; &lt;/div&gt; &lt;div class='container'&gt; &lt;label for='message' &gt;Message*:&lt;/label&gt;&lt;br/&gt; &lt;textarea rows="10" cols="50" name='message' id='message'&gt;&lt;?php echo $formproc- &gt;SafeDisplay('message') ?&gt;&lt;/textarea&gt; &lt;span id='contactus_message_errorloc' class='error'&gt;&lt;/span&gt; &lt;/div&gt; &lt;div class='container'&gt; &lt;label for='method' &gt; How would you prefer we contact you?*&lt;/label&gt;&lt;/br&gt; &lt;select name="method" id="method"&gt;&lt;?php echo $formproc-&gt;SafeDisplay('method') ?&gt; &lt;option value=""&gt;&lt;/option&gt; &lt;option value="Phone" name="phone"&gt;Phone&lt;/option&gt; &lt;option value="E-mail" name="email"&gt;E-Mail&lt;/option&gt; &lt;/select&gt;&lt;/br&gt; &lt;span id='contactus_method_errorloc' class='error'&gt;&lt;/span&gt; &lt;/div&gt; &lt;div class='container'&gt; &lt;label for='destemail' &gt; Which department are you trying to reach?*&lt;/label&gt;&lt;/br&gt; &lt;select name="destemail" id="destemail"&gt; &lt;?php foreach ($emailAddresses as $name =&gt; $email) { ?&gt; &lt;option value="&lt;?php echo htmlspecialchars($name); ?&gt;"&gt;&lt;?php echo htmlspecialchars($name) ; ?&gt;&lt;/option&gt; &lt;?php } ?&gt;&lt;/select&gt;&lt;/br&gt; &lt;span id='contactus_destemail_errorloc' class='error'&gt;&lt;/span&gt; &lt;/div&gt; &lt;input type="submit" /&gt; &lt;/fieldset&gt; &lt;/form&gt; </code></pre> <p>Help is much appreciated! Also, I'm a relatively new coder, so putting everything as simply as possible would help a lot. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload