Jump to content

Form Action Not Working


caherner987
Go to solution Solved by jazzman1,

Recommended Posts

I have 3 forms, form1.php, form2.php, form3.php...and I have three PHP pages to process each form, process1.php, process2.php, process3.php.
 
No matter what I put in the form action="process3.php" ...all three forms get processed by process1.php.  Any idea why the forms are processed by the first one?

 

The form part of FORM1.PHP:

           <form action="" method="get" id="contactForm" >
            	<table width="630" border="0" align="center">
                  <tr>
                    <td width="180" id="firstName">First Name<sup>*</sup></td>
                    <td><input name="first_name" type="text" id="firstNameVal" value="" size="60" maxlength="50" /></td>
                  </tr>
                  <tr>
                    <td id="lastName">Last Name<sup>*</sup></td>
                    <td><input name="last_name" type="text" id="lastNameVal" value="" size="60" maxlength="50" /></td>
                  </tr>
                  <tr>
                    <td>Home Phone</td>
                    <td><input name="home_phone" id="phone" type="text" value="" size="60" maxlength="50" /></td>
                  </tr>
                  <tr>
                    <td>Cell Phone</td>
                    <td><input name="cell_phone" id="cellphone" type="text" value="" size="60" maxlength="50" /></td>
                  </tr>
                  <tr>
                    <td id="email1">Email Address<sup>*</sup></td>
                    <td><input name="email1" id="emailVal1" type="text" value="" size="60" maxlength="50" /></td>
                  </tr>
                   <tr>
                    <td id="email2">Confirm Email Address<sup>*</sup></td>
                    <td><input name="email2" id="emailVal2" type="text" value="" size="60" maxlength="50" /></td>
                   </tr>
                   <tr>
                    <td>Requested Property</td>
                    <td><input name="requested_property" type="text" value="" size="60" maxlength="50" /></td>
                   </tr>
                   <tr>
                   	<td valign="top">Comments</td>
                    <td><textarea name="comments" cols="53" rows="15"></textarea></td>
                   </tr>
                   <tr>
                   	<td> </td>
                    <td style="width: 300px;">
                      <div id="error" style="color: #b94a48; background-color: #f2dede; border-color: #eed3d7; padding: 10px; ">
                        <ul id="errors" class="">  
                         <li id="info">There were some problems with your form submission:</li>  
                        </ul>
                      </div>
                      <div id="success" style="padding: 10px;  color: #468847; background-color: #dff0d8; border-color: #d6e9c6;"><p>Thanks for your message!<br/>We will get back to you ASAP!</p></div>
                    </td>
                    </tr>
                  <tr>
                    <td> </td>
                   	<td style="width:250px;"><input id="sendData" name="Submit" type="button" value="Submit" />  <input name="Reset" type="Reset" value="Reset" /></td>                  
                 </tr>
                  </tr>
                </table>
            </form>

PROCESS1.PHP

<?php
header('Access-Control-Allow-Origin: *');
header('Content-type: text/html; charset=utf-8');
if( isset($_GET) ){
	
	//form validation vars
	$formok = true;
	$errors = array();
	
	//sumbission data
	$ipaddress = $_SERVER['REMOTE_ADDR'];
	$date = date('d/m/Y');
	$time = date('H:i:s');
	
	//form data
	extract($_GET);

	
	
	//validate name is not empty
	if(empty($first_name)){
		$formok = false;
		$errors[] = "You have not entered a first name";
	}
	//validate name is not empty
	if(empty($last_name)){
		$formok = false;
		$errors[] = "You have not entered a last name";
	}
	
	//validate email address is not empty
	if(empty($email1)){
		$formok = false;
		$errors[] = "You have not entered an email address";
	//validate email address is valid
	}elseif(!filter_var($email1, FILTER_VALIDATE_EMAIL)){
		$formok = false;
		$errors[] = "You have not entered a valid email address";
	}

	//validate email address is not empty
	if(empty($email2)){
		$formok = false;
		$errors[] = "You have not entered an email address";
	//validate email address is valid
	}elseif(!filter_var($email2, FILTER_VALIDATE_EMAIL)){
		$formok = false;
		$errors[] = "You have not entered a valid email address";
	}

	if($email1 != $email2){
	  $formok = false;
	  $errors[] = "Emails are not equal";	
	}

	//send email if all is ok
	if($formok){
		
		$for = 'info@xxx.com';		//'info@xxx.com';		
		$title = "Form Title";
		$headers = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		
		$emailbody = "<p>You have recieved a new message from the contact form on your website.</p>		              
					  <p><strong>First name: </strong> {$first_name} </p>
					  <p><strong>Last name: </strong> {$last_name}</p>
					  <p><strong>Home phone: </strong> {$home_phone}</p>					 
					  <p><strong>Cell phone: </strong> {$cell_phone}</p>					 
					  <p><strong>Email: </strong> {$email1}</p>					 
					  <p><strong>Requested property: </strong> {$requested_property}</p>					 
					  <p><strong>Comments: </strong> {$comments}</p>					 
					  <p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";
              
		$headers .= 'From: XXX <info@xxx.ca>'."\r\n";				
		
		mail($for,$title,$emailbody,$headers);		


		$for = $email1;		
		$title = "Form Title";
		$headers = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		
		$emailbody = "<p>Thanks for your message!<br>We will get back to you ASAP!</p>					 
					  <p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";
              
		$headers .= 'From: XXX <no-reply@xxx.ca>'."\r\n";				
		
		mail($for,$title,$emailbody,$headers);	
		
	}
	
	//what we need to return back to our form
	$returndata = array(
		'posted_form_data' => array(
			'name' => $name,
			'email' => $email,
			'telephone' => $telephone,
			'enquiry' => $enquiry,
			'message' => $message
		),
		'form_ok' => $formok,
		'errors' => $errors
	);
		
	
	//if this is not an ajax request
	if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) !== 'xmlhttprequest'){
		//set session variables
		session_start();
		$_SESSION['cf_returndata'] = $returndata;
		
		//redirect back to form
		header('location: ' . $_SERVER['HTTP_REFERER']);
	}
    $js_array = json_encode($errors);
	echo $js_array;
}


Thanks! Craig

Link to comment
Share on other sites

The only javascript is this bit at the bottom of the page. The rest of the page only contains include files, and these include files are straight html for the header and footer.

  <script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
  <script src="js/jquery.maskedinput.min.js"></script>  
  <script src="js/custom.js"></script>
  <script type="text/javascript">
   jQuery(function($){
     $("#phone").mask("999 999 9999");
     $("#cellphone").mask("999 999 9999");
  });
  </script>
Link to comment
Share on other sites

  • Solution

What happens if you change:

<input id="sendData" name="Submit" type="button" value="Submit" />

to 

<input type="submit" value="Submit" />

Because, I don't see where is your submit type.

 

Or, if you want to use a httml button element:

<button name="button" type="submit">Click me</button>
Edited by jazzman1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.