verify required fields (dynamic text fields)
Posted: Fri Mar 09, 2012 9:33 am
here's my code for static text field:
my problem is how can i apply this if my text fields are dynamic?
let's say in my index.html there's a button that ask how many quiz are there. so if i put 2, 2 text fields are generate w/ name property ="quiz"
how can i apply this array looping in the above codes?
~~~~~~~~~~~~~~~PS:
here's the folder containing my work. i know its wrong to post download links but i swear i don't have any bad intentions. this is just for a better vision of what i'm trying to do
http://www.mediafire.com/?gbhicntq4kknnhv
index=home
calculation=page for the calculation
handler=process codes
Code: Select all
function displayerror($fieldname, $errormsg)
{
global $errorcount;
echo "Error for $fieldname: $errormsg<br />";
$errorcount++;
}
function validateinput($data, $fieldname)
{
global $errorcount;
$totalquiz=($_POST['totalquiz']);
if(empty($data))
{
displayerror($fieldname, "This field is required" . "<br>");
$errorcount=1;
$retval="";
}
else
{
$retval = trim($data);
$retval = stripslashes($retval);
if(!is_numeric($totalquiz))
{
displayerror($fieldname, "This field should be numeric" . "<br>");
$errorcount=1;
}
}
return($retval);
}
$totalquiz=validateinput($_POST['totalquiz'], "Total # of quizzes");
if($errorcount>0)
echo "please use the back button to re-enter the data" . "<br>";
else
{
echo $totalquiz;let's say in my index.html there's a button that ask how many quiz are there. so if i put 2, 2 text fields are generate w/ name property ="quiz"
how can i apply this array looping in the above codes?
~~~~~~~~~~~~~~~PS:
here's the folder containing my work. i know its wrong to post download links but i swear i don't have any bad intentions. this is just for a better vision of what i'm trying to do
http://www.mediafire.com/?gbhicntq4kknnhv
index=home
calculation=page for the calculation
handler=process codes