www.webdeveloper.com
Results 1 to 2 of 2

Thread: Contact Us form redirect to home page after submit

Hybrid View

  1. #1

    Contact Us form redirect to home page after submit

    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.
    Code:
    <?php
        
        if(!$_POST) exit;
        
        $email = $_POST['email'];
        
        
        //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
        if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
        	$error.="Invalid email address entered";
        	$errors=1;
        }
        if($errors==1) echo $error;
        else{
        	$values = array ('name','email','message','phone');
        	$required = array('name','email','message','phone');
        	 
        	$your_email = "todd@toddandersonhomes.com";
        	$email_subject = "Free Credit Report: ".$_POST['subject'];
        	$email_content = "Following is the free credit report detail from client:\n";
        	
        	foreach($values as $key => $value){
        	  if(in_array($value,$required)){
        		if ($key != 'subject' && $key != 'company') {
        		  if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
        		}
        		$email_content .= $value.': '.$_POST[$value]."\n";
        	  }
        	}
        	 
        	if(@mail($your_email,$email_subject,$email_content)) {
        		echo 'Message sent!'; 
        	} else {
        		echo 'ERROR!';
        	}
        }
        ?>
    HTML Code:

    HTML Code:
    <form action="contact.php" method="post">
        
                                <div class="formele">
                        <ul>
                            <li>
                            <label>Name:</label>
                            <input type="text" id="name" name="name" class="text2" />
                            </li>
                            <li>
                            <label>Telephone:</label>
                            <input id="name" type="text" name="phone" class="text2" />
                            </li>
                            <li>
                            <label>E-mail:</label>
                            <input id="name" type="text" name="email" class="text2" />                    
                            </li>
                            <li>
                            <label>Address:</label>
                            <input id="name" type="text" name="message" class="text2" />                    
                            </li>
                            
                            <li class="button">
                            <input type="image" type="text" src="images/submit.png" />                  
                            </li>
                        </ul>           
                    </div><!--Contact Form Ends Here -->
                    </form>
    Here is the link of the page: http://www.designsblessing.com/Landingpages/

  2. #2
    Join Date
    Nov 2011
    Posts
    37
    at the end of your php script, put

    header("Location: hompage.php")

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles