October 21, 200917 yr Hi after some advice please i have a single page site with contact form and php script is there anyway after submitting the form that the url will stay the same i dont wont to go to /sendmail.php in my url
October 21, 200917 yr can you post your code, you can have the php do the work on the same page as the contact form, you just tell the form to stay on the same page along the lines of <form method="post" action"<?php $_SERVER[php_SELF]; ?>"> you would name the page contact.php and then have the php stuff at the top of the page
October 21, 200917 yr Author can you post your code, you can have the php do the work on the same page as the contact form, you just tell the form to stay on the same page along the lines of <form method="post" action"<?php $_SERVER[php_SELF]; ?>"> you would name the page contact.php and then have the php stuff at the top of the page form action="contact.php" method="post" name="contact" class="contact" > <div class="box"> <label> <span>Full name</span> <input type="text" class="input_text" name="name" id="name"/> </label> <label> <span>Email</span> <input type="text" class="input_text" name="email" id="email"/> </label> <label> <span>Subject</span> <input type="text" class="input_text" name="subject" id="subject"/> </label> <label> <span>Message</span> <textarea class="message" name="feedback" id="feedback"></textarea> <input type="submit" value="Send Message" name="submit" class="submit" /> </label> </div> </form>
October 21, 200917 yr form action="contact.php" method="post" name="contact" class="contact" > <div class="box"> <label> <span>Full name</span> <input type="text" class="input_text" name="name" id="name"/> </label> <label> <span>Email</span> <input type="text" class="input_text" name="email" id="email"/> </label> <label> <span>Subject</span> <input type="text" class="input_text" name="subject" id="subject"/> </label> <label> <span>Message</span> <textarea class="message" name="feedback" id="feedback"></textarea> <input type="submit" value="Send Message" name="submit" class="submit" /> </label> </div> </form> I meant the PHP code, sorry
October 21, 200917 yr Author I meant the PHP code, sorry <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "sjackson@"; $email_subject = "Your email subject line"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form your submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['tel']) || !isset($_POST['enquiry'])) { died('We are sorry, but there appears to be a problem with the form your submitted.'); } $first_name = $_POST['name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['tel']; // not required $comments = $_POST['enquiry']; // required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } $string_exp = "^[0-9 .-]+$"; if(!eregi($string_exp,$telephone)) { $error_message .= 'The Telphone Number you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($first_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Tel: ".clean_string($telephone)."\n"; $email_message .= "enquiry: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> cheers for your help
October 21, 200917 yr <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "sjackson@"; $email_subject = "Your email subject line"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form your submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['tel']) || !isset($_POST['enquiry'])) { died('We are sorry, but there appears to be a problem with the form your submitted.'); } $first_name = $_POST['name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['tel']; // not required $comments = $_POST['enquiry']; // required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } $string_exp = "^[0-9 .-]+$"; if(!eregi($string_exp,$telephone)) { $error_message .= 'The Telphone Number you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($first_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Tel: ".clean_string($telephone)."\n"; $email_message .= "enquiry: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> cheers for your help Hey all you have to do is put the code that you want to process the form all on one page includeing the form it self and then in the start form tag put the action as <form method="POST" action="<?php $_SERVER['PHP_SELF'] ?>"
Create an account or sign in to comment