Page 1 of 1

checkbox validation

Posted: Tue Dec 30, 2008 10:10 am
by kabucek
hello,

i have this piece of code:





Code: Select all

 
 
         <table border=0 cellspacing='0' cellpadding='0' class='paragraph' style=margin-top:20pt; width='1146'>
         
         
         
         <tr valign='top'>
      <td width='201'   height='26' align='left' $fieldLabelStyleString><div align='left'><font color='black'>Certyfying Organization</font>{$errorArray["cprorgname"]}</div>
        <td  height='26' align=left width='945'><input type='text' name='otherInfoArray[cprorgname]' value='{$otherInfoArray['cprorgname']}'>
         Type of CPR  <font face='Arial, Helvetica, sans-serif' size='1' color='red'><em>*</em></font>
         Adult CPR   <input type='checkbox' name='otherInfoArray[cpradult]' value='{$otherInfoArray['cpradult']}'>
       Child CPR   <input type='checkbox' name='otherInfoArray[cprchild]' value='{$otherInfoArray['cprchild']}'>
       Infant CPR   <input type='checkbox' name='otherInfoArray[cprinfant]' value='{$otherInfoArray['cprinfant']}'>
      </td>
     </tr>
         
         
         
         <tr valign='top'>
      <td width='26'   height='26' align='left' $fieldLabelStyleString><div align='left'><font color='black'>Issue Date</font>{$errorArray["cprissuedate"]}</div>
        <td  height='26' align=left width='26'><input type='text' name='otherInfoArray[cprissuedate]' value='{$otherInfoArray['cprissuedate']}'>
        Expiration Date {$errorArray["cprexpdate"]}<input type='text' name='otherInfoArray[cprexpdate]' value='{$otherInfoArray['cprexpdate']}'> <br>
        I attest that I have renewed my CPR certification and will submit documentation to that effect upon request.<font face='Arial, Helvetica, sans-serif' size='1' color='red'><em>*</em></font>
        Yes   <input type='checkbox' name='otherInfoArray[cprattestyes]' value='{$otherInfoArray['cprattestyes']}'>
      No  <input type='checkbox' name='otherInfoArray[cprattestno]' value='{$otherInfoArray['cprattestno']}'>
        </td>
     </tr>
        
                
        </table>
 
        
 
       <DIV style='font-size:110%;text-align:left;margin-top:15pt;'>
                      <font face='Arial Black, Helvetica, sans-serif' size='5' color='black'>SUGGESTIONS/COMMENTS </font>                   
           </div>
           
and I want for people to check the cprattestyes box and go next.
if they do not check that box they will not go next

thanks

Re: checkbox validation

Posted: Tue Dec 30, 2008 12:55 pm
by califdon
Probably the easiest way would be to change those two <input> elements to be type="button" and then put your next page as the jump page in the onClick event of the Yes button, and do whatever you want for the No button. You could also put the checkboxes inside a <form> element, and add a Submit button, and make the next page the action= value of the form. Then in the next page, you could check to see which checkbox had been checked and only display the rest of the page if the Yes button had been checked.

Re: checkbox validation

Posted: Tue Dec 30, 2008 1:05 pm
by kabucek
ok,

I'm using another .php page to validate fields from the array with this:

Code: Select all

$validationArrayDefinitionString="       validationArray[inx]=new validationElement('memberDataArray[first]', 'First Name', '', 'required'); inx++;     validationArray[inx]=new validationElement('memberDataArray[last]', 'Last Name', '', 'required'); inx++;      validationArray[inx]=new validationElement('memberDataArray[street1]', 'Address', '', 'required'); inx++;      validationArray[inx]=new validationElement('memberDataArray[city]', 'City', '', 'required'); inx++;      validationArray[inx]=new validationElement('memberDataArray[state]', 'State', '', 'required'); inx++;      validationArray[inx]=new validationElement('memberDataArray[zip]', 'zip', '', 'required'); inx++;
";

is there a way, in which I can use above suggestions to make the validation work?

thanks

Re: checkbox validation

Posted: Tue Dec 30, 2008 1:34 pm
by kabucek
this is easy to say,
harder to do.

Re: checkbox validation

Posted: Tue Dec 30, 2008 2:07 pm
by califdon
I can't understand what you're doing there, since all you have shown is how to construct a long string, and I have no idea why.

If you're already creating a form and submitting it to another script, then in that script you could also check which of the checkboxes were checked, doing that even before any other validation. If the Yes box was not checked, you could send the user to a "Not Authorized" page or something.

Re: checkbox validation

Posted: Tue Dec 30, 2008 2:56 pm
by kabucek
sorry, i'm a little tired.

I want to have 2 checkboxes: Yes & No

and I want the following actions:

- if someone choose No - error message: " you need to accept"
- if checkbox is not selected - error message: " you forgot to accept"

i want the fieldname to be:

otherInfoArray[cprattestyes] & otherInfoArray[cprattestno]


thanks.

Re: checkbox validation

Posted: Tue Dec 30, 2008 6:32 pm
by califdon
It all depends on how you want to notify the user. Here's a general pattern that might be helpful:

Code: Select all

<?php
if(isset($_POST['otherInfoArray[cprattestyes]']) {
    echo "OK, you can continue";
} else {
    echo "You did not accept":
    header('Location: http://www.example.com/');
}
... // rest of your script, if successful
 
If I were writing the script, I don't think I would use array elements as names for HTML elements, it just complicates the programming. And why would it be important to know the difference between nothing checked and "No" checked? You're going to take the same action in either case, aren't you? Why not just leave off the No checkbox? That's just inviting the user to make a mistake by checking the wrong box. Presumably no one should ever think they are supposed to check the No box.