...

View Full Version : Please Check this Code - Urgent



loooolaaaaa
08-26-2006, 04:18 PM
i have created a php form to add the details of System. When Submit button is clicked the validation is not synchronizing properly. Somebody please check the code and help me ... Its urgent


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Register</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="images/style.css" rel="stylesheet" type="text/css" />
</head>
<Script Language="JavaScript" >
var Validation = new Array();
//Validation[0] = []; // hidden input
Validation[0] = [["required", "Please Enter a Valid IPaddress"], ["minlen=2", "Your Username is too short!"]];
Validation[1] = [["required", "Please Enter a Hostname"], ["minlen=3", "Your Password is too short!"],["alnum","Hostname cannot be numbers !"]];
Validation[2] = [["required", "Please Enter the Model"], ["minlen=3", "Your Username is too short!"]];
Validation[3] = [["required", "Please enter No. of Processors"], ["minlen=1", "Your Password is too short!"],["numeric", "Processor should be numbers !"]];
Validation[4] = [["required", "Please enter the RAM Speed"], ["minlen=2", "Your date is Invalid !"],["numeric", "Your date is Invalid !"]];

Validation[5] = [["required", "Please enterProcessor Speed"], ["minlen=4", "Your year is Invalid !"],["numeric", "Your year is Invalid !"]];



function validateIP(ip_addr)
{
var re = new RegExp(/^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/);
if(ip_add.match(re) != null)
{
return true;
}
return false;
}

/* function validateData
* Checks each field in a form
* Called from validateForm function
*/
function validateData(strValidateStr,objValue,strError)
{
var epos = strValidateStr.search("=");
var command = "";
var cmdvalue = "";
if(epos >= 0)
{
command = strValidateStr.substring(0,epos);
cmdvalue = strValidateStr.substr(epos+1);
}
else
{
command = strValidateStr;
}

switch(command)
{
case "req":
case "required":
{
if(eval(objValue.value.length) == 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : Required Field";
}//if
alert(strError);
return false;
}//if
break;
}//case required
case "maxlength":
case "maxlen":
{
if(eval(objValue.value.length) > eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : "+cmdvalue+" characters maximum ";
}//if
alert(strError);
return false;
}//if
break;
}//case maxlen
case "minlength":
case "minlen":
{
if(eval(objValue.value.length) < eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : " + cmdvalue + " characters minimum ";
}//if
alert(strError);
return false;
}//if
break;
}//case minlen
case "alnum":
case "alphanumeric":
{
var charpos = objValue.value.search("[^A-Za-z0-9]");
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Only alpha-numeric characters allowed ";
}//if
alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
return false;
}//if
break;
}//case alphanumeric
case "num":
case "numeric":
{
var charpos = objValue.value.search("[^0-9]");
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Only digits allowed ";
}//if
alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
return false;
}//if
break;
}//numeric
case "alphabetic":
case "alpha":
{
var charpos = objValue.value.search("[^A-Za-z]");
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Only alphabetic characters allowed ";
}//if
alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
return false;
}//if
break;
}//alpha
case "alnumhyphen":
{
var charpos = objValue.value.search("[^A-Za-z0-9\-_]");
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _";
}//if
alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
return false;
}//if
break;
}
case "ip_addr":
{
if(!validateIP(objValue.value))
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Enter a valid IP Address ";
}//if
alert(strError);
return false;
}//if
break;
}//case IP_addr
case "lt":
case "lessthan":
{
if(isNaN(objValue.value))
{
alert(objValue.name+": Should be a number ");
return false;
}//if
if(eval(objValue.value) >= eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : value should be less than "+ cmdvalue;
}//if
alert(strError);
return false;
}//if
break;
}//case lessthan
case "gt":
case "greaterthan":
{
if(isNaN(objValue.value))
{
alert(objValue.name+": Should be a number ");
return false;
}//if
if(eval(objValue.value) <= eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + " : value should be greater than "+ cmdvalue;
}//if
alert(strError);
return false;
}//if
break;
}//case greaterthan
case "regexp":
{
if(!objValue.value.match(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Invalid characters found ";
}//if
alert(strError);
return false;
}//if
break;
}//case regexp
case "dontselect":
{
if(objValue.selectedIndex == null)
{
alert("BUG: dontselect command for non-select Item");
return false;
}
if(objValue.selectedIndex == eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Please Select one option ";
}//if
alert(strError);
return false;
}
break;
}//case dontselect
}//switch
return true;
}

/*
* function validateForm
* the function that can be used to validate any form
* returns false if the validation fails; true if success
* arguments :
* objFrm : the form object
* arrObjDesc : an array of objects describing the validations to conduct on each
* input item.
* The array should consist of one object per input item in the order the input
* elements are present in the form. Each object consist of zero or more validation
* objects. Each of these validation object is a pair consisting of the validation
* descriptor string and an optional Error message.
*/

function validateForm(objFrm,arrObjDesc)
{


for(var itrobj=0; itrobj < arrObjDesc.length; itrobj++)
{
if(objFrm.elements.length <= itrobj)
{
alert("BUG: Obj descriptor for a non existent form element");
return false;
}//if
for(var itrdesc=0; itrdesc < arrObjDesc[itrobj].length ;itrdesc++)
{
if(validateData(arrObjDesc[itrobj][itrdesc][0],
objFrm[itrobj],arrObjDesc[itrobj][itrdesc][1]) == false)
{
objFrm[itrobj].focus();
return false;
}//if
}//for
}//for
return true;
}


</script>




<body >

<div id="HEADER">
<h1><a href="#">Company&nbsp;Name</a></h1>
<ul>

<li><a href="Add.php">Add System</a></li>
</ul>
</div> <!-- header -->

<div id="PATH">
<p><a href="index.php"><b>Home</b></a> <span class="Arrow">&raquo;</span> Add System </p>
</div> <!-- PATH -->
<!-- sidebar -->
<div id="SIDEBAR1">
<h1>Add New System </h1>
<div align="center">
<form name="form_add" method="post" action="Add.php" onsubmit="return validateForm(this, Validation)" >
<p>
<label>IP Address &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
<input name="ip_addr" type="text" id="ip_addr" />
</label>
</p>
<p>
<label>
Hostname&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
<input name="hname" type="text" id="hname" />
</label>
</p>
<p>
<label>
Model &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="model" type="text" id="model" />
</label>
</p>
<p>
<label>
Processors&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="pro" type="password" id="pro" />
</label>
</p>
<p>
<label>
Ram&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="ram" type="text" id="ram" />
</label>
</p>
<p>
<label> Processor Speed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="pspeed" type="text" id="pspeed" />
</label>
</p>
<p>
<label> </label>
</p>

<p>&nbsp;</p>
<p> <label>
<input name="Add" type="submit" id="Add" value="Add System" />
</label>
</p>
<p>&nbsp;</p>
</div>
</form>
</div>

<!-- content -->
</body>
</html>

Philip M
08-26-2006, 04:46 PM
This is the second time in a matter of days that you have chosen to ignore the posting guidelines.

Please read them at:-
http://www.codingforums.com/showthread.php?t=2090

loooolaaaaa
08-26-2006, 05:24 PM
I m really soory i have read the document, i need that code urgently so could be help me out. from past three days i m struggling with it

Philip M
08-27-2006, 08:16 AM
Validation[2] = [["required", "Please Enter the Model"], ["minlen=3", "Your Username is too short!"]];
Validation[3] = [["required", "Please enter No. of Processors"], ["minlen=1", "Your Password is too short!"],["numeric", "Processor should be numbers !"]];
Validation[4] = [["required", "Please enter the RAM Speed"], ["minlen=2", "Your date is Invalid !"],["numeric", "Your date is Invalid !"]];

Validation[5] = [["required", "Please enterProcessor Speed"], ["minlen=4", "Your year is Invalid !"],["numeric", "Your year is Invalid !"]];

This extract does not give me confidence that you wrote this code yourself.
As you you not give any clue as to what the problem is I feel that is as far as can be gone.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum