Hi, I got this scripts from this
URL
There is Error when i submit the form.
Line: 54
Error: 'document.getElementbyID(....)' is null or not an object
What is this error.
Complete Files
index.php
[PHP]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Ajax Form</title>
<script type="text/javascript" src="validate.js"></script>
</head>
<body>
<fieldset>
<legend>Ajax Form</legend>
<form name="form1" id="form1" method="post" action="formvalidation.php?validationtype=php" onSubmit="return validate();">
<table width="500">
<tr>
<td width="130">Username </td>
<td width="170"><input type="text" name="user" tabindex="1" id="user" class="validate required none usermsg"/></td>
<td id ="usermsg" class="rules">Required</td>
</tr>
<tr>
<td>Email </td>
<td><input type="text" name="email" tabindex="2" id="email" class="validate required email emailmsg" /></td>
<td id="emailmsg" class="rules">Required</td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit" tabindex="5" /></td>
</tr>
</table>
</form>
</fieldset>
</body>
</html>
[/PHP]
formvalidation.php
[PHP]<?php
//After the form is submitted or onblur, request the validation type
$validationtype = $_GET["validationtype"]; //validationtype is ajax or php
$continueSubmit = true ; //global var if the form is valid. used only for php validationtype.
switch ($validationtype)
{
case 'ajax':
ProcessAjax(); //if validationtype is ajax go to processajax function
break;
case 'php':
processPHP();//if it is php call processphp runction
break;
}
function ProcessAjax()
{
$required = $_GET["sRequired"];//$required holds if the field is required. will be "required" or "notrequired"
$typecheck = $_GET["sTypeCheck"];//$typecheck holds additional requirements like email or phone
$val = $_GET["val"];
//validateRequired checks if it is required and then sends back feedback
validateRequired($required,$val,$typecheck);
/*check to see which typecheck (eg. email, date, etc.) was entered as the second variable in the validateMe() function
check the different cases passed in from the validateMe function. Send back the appropriate information*/
switch ($typecheck)
{
case 'date':
validateDate($val);
break;
case 'email':
validateEmail($val);
break;
}
}
//If the url string value for validationtype was PHP, you will be validating through this server side function
function processPHP()
{
//request the forms variables
$user = $_POST["user"];
$email= $_POST["email"];
global $continueSubmit;
//check to see if the different form fields are valid
echo "Username: ";
validateRequired("required", $user, "none");//validate user
echo "<br />";
echo "Email: ";
validateEmail($email) ;//validate email
//if continue is not 0 then continue with the form submission
if ($continueSubmit)
{
//submit your form
}
}
//--------------------------VALIDATION FUNCTIONS -----------------
//Function to validate if the field is required. It just checks to see if the field is empty.
function validateRequired($required,$val,$typecheck)
{
// if it is required check to see if it validates
if ($required == "required")
{
if ($val == "")
{
// if val is blank then then the field is invalid
echo "Required";
exit(); //we do not need to check for anything else so exit the validation
}
if ($val !== "" && $typecheck == "none")
{
// if val is not blank and there are no further validation checks ("none") respond with a thank you for feedback
echo "Thank You";
}
}
// if it is not required or typecheck is not none, the script will continue to validate
}
function validateEmail($val)
{
global $continueSubmit ;
// check the email address with a regex function
//regular expression is from http://regexlib.com/.
//To learn more about them, http://www.silverstones.com/thebat/Regex.html#intro has a pretty good tutorial
if (ereg ("^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$", $val, $regs))
{
echo "Thank You";
}
else
{
$continueSubmit = false;
echo "Invalid Email Address";
}
}
[/PHP]
validate.js