Jump to content

form validation


kev wood

Recommended Posts

i have created a website which loads the page content into a div tag.  the problem i am having is that two sections of the content are forms and i would like to have some form validation on these but everything i have tried up to now has failed.

 

the code i have so far is as follows

 

the head section

 

	   function validateFormOnSubmit(sub_form) {
	var reason = "";

	  reason += validateFirstname(theForm.fname);
	  reason += validateSurname(theForm.lname);
	  reason += validateEmail(theForm.email);
      
	  if (reason != "") {
		alert("Some fields need correction:\n" + reason);
		return false;
	  }

	  return true;
	}

		   function validateFormOnSubmit(interest) {
	var reason = "";

	  reason += validateFirstname(theForm.radio);
	  reason += validateSurname(theForm.name);
	  reason += validateEmail(theForm.address);
	  reason += validateEmail(theForm.housing);
	  reason += validateEmail(theForm.email);
      
	  if (reason != "") {
		alert("Some fields need correction:\n" + reason);
		return false;
	  }

	  return true;
	}

 

this code is in the head section of the index page which has all the code loaded into it.  i have set the code out with the names of the forms in the brackets at the end of the function line so it would only use the correct validation for each form.  i am not sure that this is correct though.

 

and the code for the forms is as follows

 

case 9:
		echo '<form name="sub_form" action="i*******.php" onsubmit="return validateFormOnSubmit(this)" method="POST">

	<h4>Select what page you would like notifying about on update</h4>
	    <select name="radio">
	  		<option value="news">News Article</option>
	  		<option value="training">Training Opportunities</option>
	  		<option value="events">Event</option>
	    </select>
	    <br /><br /><h4>Enter the required information</h4>
	    <b>First Name:</b><br />
	    <input type="text" name="fname" /><br />
	    <b>Last Name:</b><br />
	    <input type="text" name="lname" /><br />
	   <b>Email:</b><br />
	   <input type="text" name="email" /><br />
	   <br />
	   <input type="submit" value="Add subscription" />
	      </p>
	</form>';
		break;

Link to comment
https://forums.phpfreaks.com/topic/152073-form-validation/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.