Note that there are some explanatory texts on larger screens.

plurals
  1. POJS message in PHP return to HTML page
    primarykey
    data
    text
    <p>HTML Code</p> <pre><code>&lt;div id="fourmstyle" class="fourm"&gt; &lt;form action="scripts/mail.php" method="post"&gt; &lt;label for="name"&gt;Your Name &lt;required&gt;*&lt;/required&gt; &lt;/label&gt; &lt;input type="text" name="Name" id="Name" placeholder="Joe Bloggs"&gt; &lt;label for="email"&gt;Your Email &lt;required&gt;*&lt;/required&gt; &lt;/label&gt; &lt;input type="text" name="Email" id="Email" placeholder="Joebloggs@example.com"&gt; &lt;label for="telephone"&gt;Telephone &lt;/label&gt; &lt;input type="text" name="Telephone" id="Telephone"&gt; &lt;label for="type"&gt;Type &lt;/label&gt; &lt;select name="Type"&gt; &lt;option value="Booking" selected&gt;Booking&lt;/option&gt; &lt;option value="B&amp;B"&gt;B&amp;amp;B&lt;/option&gt; &lt;option value="Question"&gt;Question&lt;/option&gt; &lt;option value="General"&gt;General&lt;/option&gt; &lt;option value="Website Feedback"&gt;Website Feedback&lt;/option&gt; &lt;/select&gt;&lt;/p&gt; &lt;label for="messsage"&gt;Message &lt;required&gt;*&lt;/required&gt; &lt;/label&gt; &lt;textarea name="Message" id="Message" rows="5" cols="25"&gt; &lt;/textarea&gt;&lt;/p&gt; &lt;label for="btn"&gt;&amp;nbsp;&lt;/label&gt; &lt;button type="submit" class="button"&gt;Submit &lt;/button&gt; &lt;br&gt;&amp;nbsp;&lt;requireddescription&gt; *(indicates that the information is required) &lt;/requireddescription&gt; &lt;/form&gt; </code></pre> <p>PHP Code</p> <pre><code>&lt;?php if(isset($_POST)) { $name = (isset($_POST['Name'])) ? strip_tags($_POST['Name']) : NULL; //if name is set, strip html tags, and return it, otherwise set the string as NULL. $email = (isset($_POST['Email'])) ? strip_tags($_POST['Email']) : NULL; //same as above. $telephone = (isset($_POST['Telephone'])) ? preg_replace('~[^0-9\-]~','',$_POST['Telephone']) : NULL; //if telephone is set, remove any characters that are not a number, or a dash, othewise set as NULL. $type = (isset($_POST['Type'])) ? strip_tags($_POST['Type']) : NULL; //strip tags. $message = (isset($_POST['Message'])) ? strip_tags($_POST['Message']) : NULL; //strip tags. if(empty($name) || empty($email) || empty($message)) { //name, email, and message are required fields, if they are empty, tell the user to go back and fill them in. echo '&lt;script type="text/javascript"&gt; alert ("Please go back and fill in all required lines"); &lt;/script&gt;'; } else { //if the fields are NOT empty, proceed with the mailing. $formcontent=" From: $name \n Type: $type \n\n Message: $message \n\n Telephone: $telephone"; $recipient = "joebloggs@example.com"; $subject = "Website Contact Form: $type"; $mailheader = "From: $email \r\n"; if(mail($recipient, $subject, $formcontent, $mailheader)) { //if mail is sent to the SMTP server successfully, echo 'thank you'. echo '&lt;script type="text/javascript"&gt; alert ("Thankyou '.$name.' we have submitted your message and we will get back to you as soon as possible, if you need to speak to us in the mean time please call 01983 872244 "); &lt;/script&gt;'; } else { //otherwise, tell the user it did not go through. echo '&lt;script type="text/javascript"&gt; alert ("I am sorry but there has been an error submitting your request please try again or call us on 01983 872244"); &lt;/script&gt;'; } } } ?&gt; </code></pre> <p>Ok so my code above works quite nicely and I have JS pop up alerts. However, when I ok the JS alert it takes me back to the mail.php script and not the HTML page in which it originated from how would I rectify this ? </p>
    singulars
    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.
 

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