Sunday, 8 July 2012

Contact Us form redirect to home page after submit (Web Development)


I have developed a contact us page and also PHP code that works perfect. Know the only problem is that after submitting the form it shows only "Message sent" on a new page. I want that after submitting the form page will redirect back to home page. It is only one page "Landing Page". Here is the PHP code.`
  1. <?php
  2. if(!$_POST) exit;
  3. $email = $_POST['email'];
  4. //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
  5. if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
  6. $error.="Invalid email address entered";
  7. $errors=1;
  8. }
  9. if($errors==1) echo $error;
  10. else{
  11. $values = array ('name','email','message','phone');
  12. $required = array('name','email','message','phone');
  13. $your_email = "todd@toddandersonhomes.com";
  14. $email_subject = "Free Credit Report: ".$_POST['subject'];
  15. $email_content = "Following is the free credit report detail from client:\n";
  16. foreach($values as $key => $value){
  17. if(in_array($value,$required)){
  18. if ($key != 'subject' && $key != 'company') {
  19. if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
  20. }
  21. $email_content .= $value.': '.$_POST[$value]."\n";
  22. }
  23. }
  24. if(@mail($your_email,$email_subject,$email_content)) {
  25. echo 'Message sent!';
  26. } else {
  27. echo 'ERROR!';
  28. }
  29. }
  30. ?>
HTML Code:
  1. <form action="contact.php" method="post">
  2. <div class="formele">
  3. <ul>
  4. <li>
  5. <label>Name:</label>
  6. <input type="text" id="name" name="name" class="text2" />
  7. </li>
  8. <li>
  9. <label>Telephone:</label>
  10. <input id="name" type="text" name="phone" class="text2" />
  11. </li>
  12. <li>
  13. <label>E-mail:</label>
  14. <input id="name" type="text" name="email" class="text2" />
  15. </li>
  16. <li>
  17. <label>Address:</label>
  18. <input id="name" type="text" name="message" class="text2" />
  19. </li>
  20. <li class="button">
  21. <input type="image" type="text" src="images/submit.png" />
  22. </li>
  23. </ul>
  24. </div><!--Contact Form Ends Here -->
  25. </form>
Here is the link of the page: http://www.designsblessing.com/Landingpages/

  1. <?php
  2. if(!$_POST) exit;
  3. $email = $_POST['email'];
  4. //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
  5. if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
  6. $error.="Invalid email address entered";
  7. $errors=1;
  8. }
  9. if($errors==1) echo $error;
  10. else{
  11. $values = array ('name','email','message','phone');
  12. $required = array('name','email','message','phone');
  13. $your_email = "todd@toddandersonhomes.com";
  14. $email_subject = "Free Credit Report: ".$_POST['subject'];
  15. $email_content = "Following is the free credit report detail from client:\n";
  16. foreach($values as $key => $value){
  17. if(in_array($value,$required)){
  18. if ($key != 'subject' && $key != 'company') {
  19. if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
  20. }
  21. $email_content .= $value.': '.$_POST[$value]."\n";
  22. }
  23. }
  24. if(@mail($your_email,$email_subject,$email_content)) {
  25. echo 'Message sent!';
  26. } else {
  27. echo 'ERROR!';
  28. }
  29. }
  30. ?>

No comments:

Post a Comment