turpentyne 0 Newbie Poster

help! I'm trying to figure out how to verify looped form fields by name. This seems like it should work, but it's just skipping right past this verification step. Here's the code:

     <?php
    session_start();
    ?>
     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">



    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>


     <script type='text/javascript'>


function myForm(){
    // Make quick references to our fields
    {
    // Make quick references to our field *ARRAYS*: 
    var fname = form["kfname[]"];
    var lname =  form["klname[]"];
    var birth_month = form["bdate2[]"];
    var birthday = form["bdate[]"];
    var birthyear = form["bdate3[]"];

    for ( var f = 0; f < fname.length; ++f )
    {
        var n = f+1;
        if(    ! isAlphabet(fname[f], "Please enter only letters for first name " +n)
            || ! isAlphabet(lname[f], "Please enter only letters for last name " +n)
            || ! madeSelection(birth_month[f], "Pleace choose a birth month for name " +n)
            || ! madeSelection(birthday[f], "Please choose a birth day for name " +n)
            || ! madeSelection(birthyear[f], "Please choose a birth year for name " +n)
        ) {
            return false;
        }
    }
    return true;
}



function isAlphabet(elem, helperMsg){
    var alphaExp = /^[a-zA-Z ]+$/;
    if(elem.value.match(alphaExp)){
        return true;
    }else{
        alert(helperMsg);
        elem.focus();
        return false;
    }
}

function isAlphanumeric(elem, helperMsg){
    var alphaExp = /^[0-9a-zA-Zs]+$/;
    if(elem.value.match(alphaExp)){
        return true;
    }else{
        alert(helperMsg);
        elem.focus();
        return false;
    }
}


function madeSelection(elem, helperMsg){
    if(elem.value == ''){
        alert(helperMsg);
        elem.focus();
        return false;
    }else{
        return true;
    }
}

</script>

</head>


/* other php code here. Then... */

    $count = $line;
     $i = 1;
while ($i <= $count) {
     $i++;  /* the printed value would be
                   $i before the increment
                   (post-increment) */
                   $x = $i-1;


    ?><form name="register1" class="registration_form" method="post" action="register2.php" target="_self" onsubmit="return myForm(this)">

    <b><?= $reg_id ?><span style='color:#777777;padding-bottom:10px;'> Child #<?= $x ?> </span></b>

    <img src="/images/greenblack.gif" style="height:2px; width:450px;position:relative;left:5px;top:-3px;"><br><br>

    <div style="float:left; padding-right:20px;">Kid's First Name<br><input type="text" name="kfname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /></div>
    <div style="float:left; padding-right:20px;">Kid's Last Name<br><input type="text" name="klname[]" id="lname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';"  /></div>

    <div>Birthdate<br><div style="">
    <select style="width:75px;" id="birth_month" name="bdate2[]" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" >
<option value="">month</option>
  <option value="01">Jan</option>
  <option value="02">Feb</option>
  <option value="03">Mar</option>

</select>


        <select style="width:57px;" id="birthday" name="bdate[]" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" >
<option value="">day</option>
  <option value="01">01</option>
  <option value="02">02</option>
  <option value="03">03</option>
  <option value="04">04</option>

</select>

<select style="width:60px;" id="birthyear" name="bdate3[]" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" >
<option value="">year</option>
  <option value="1993">1993</option>
  <option value="1994">1994</option>
  <option value="1995">1995</option>

</select></div></div>

    <br>
<input type="hidden" name="workshop_id[]"  id="workshop_id" value="<?php echo $key; ?>">
</td></tr></table><br><br>
<?php   
}
}

?><br />
<input type="submit" value="next" />
</form> 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.