Contact Us form redirect to home page after submit

Discussion in 'PHP' started by Kaleem Ullah Hashmi, Apr 24, 2012.

  1. #1
    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.

    <?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!';
        	}
        }
        ?>
        
    Code (markup):
    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>
    
    
    HTML:
    Here is the link of the page: http://www.designsblessing.com/Landingpages/
     
    Kaleem Ullah Hashmi, Apr 24, 2012 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,899
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Instead of echo'ing out message sent use a

    header('url?'.urlencode($message));

    to send the user to the home page and put a spot in the home page to test for message and to display it.

    Alternatively give the user a proper "message sent" page but put a meta redirect on it to move them on after 15 seconds or so
     
    sarahk, Apr 24, 2012 IP