Menu

Checkbox Verification?

Help
dbcom
2007-09-14
2013-06-03
  • dbcom

    dbcom - 2007-09-14

    I'm able to create a form that includes a single option checkbox, as the user is required to click the checkbox in order to submit the form, but I can't seem to get it to validate. Instead, the form is sent with or w/out the box being checked.

    Here is the HTML code:
    <li class="mainForm" id="fieldBox_100"><input class=mainForm type=checkbox name=field_100[] id=field_100_option_1 value="I agree" /><label class=formFieldOption for="field_100_option_1">I verify that the above information submitted is accurate.</label></li>

    I noticed in the script that the 'validateField' function did not include: || fieldType == 'checkbox'
    ...so I added it to the script but it still didn't trigger validation.

    I also tried setting: the last parameter below to '1', but it still didn't validate:
    if (validateField('field_100','fieldBox_100','checkbox',1) == false)
    retVal=false;

    Lastly, I tried using the form as generated with the checkbox, but received the following error message:
    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
    ...for the second line below:
    // Checkbox handling
    $field_20_opts = $_POST['field_20'][0];

    Can anyone help shed light on this?

    TIA,
    dbcom

     
    • TNTEverett

      TNTEverett - 2007-09-14

      Validating checkboxes is not part of the current version.  I can help but you will need to send me the link to your form number or send me the zip file in an email. 
      Your attempt to make it work was only partially implemented.  This part was correct
      if (validateField('field_100','fieldBox_100','checkbox',1) == false)
      retVal=false;
      but additional code needs to be added to the ValidateField function or a new function must be created to finish the modification.  I did a similar change for someone else wanting to validate RadioButtons.  Let me know if you would like me to help. 

       
      • xeyoho

        xeyoho - 2008-07-03

        Hi,

        I have a problem with validating the check box as well.(They need to check and agree terms and conditions) I also put

        if (validateField('field_100','fieldBox_100','checkbox',1) == false) 
        retVal=false;

        inside my code however I understand that I still need to put some additional code inside ValidateField function.

        would it be possible for you to help me as well? I have searched the forum for this code but I couldn't find it. I can email my files to you.

        Thank you

         
        • TNTEverett

          TNTEverett - 2008-07-03

          Upper part of the form.html where Java functions are:
          function validateCheckBox(fieldId, fieldBoxId, fieldType, required) {
            if(fieldType == 'checkbox') {
              fieldBox = document.getElementById(fieldBoxId);
              if(required == 1) {
                myfieldId = fieldId+"_option_1";
                fieldObj = document.getElementById(myfieldId);
                if(fieldObj.checked == 1) {
                  myfieldId = fieldId+"_option_1";
                  fieldObj = document.getElementById(myfieldId);
                  fieldObj.setAttribute("class","mainForm");
                  fieldObj.setAttribute("className","mainForm");
                  return true;
                } else {
                  fieldObj.setAttribute("class","mainFormError");
                  fieldObj.setAttribute("className","mainFormError");
                }
                fieldObj.focus();
                return false;
              }
            }
          }

          Lower part of form.html where validation occurs:
          if (validateCheckBox('field_2','fieldBox_2','checkbox',1) == false)
          retVal=false;

           
          • xeyoho

            xeyoho - 2008-07-07

            Thank you very much, everything works fine now....

            Just for the future references; do I use the same code if I need to validate more than 1 check box in the same fieldBox?

            Thanks again, phpFormGenerator is a great source! 

             
    • dbcom

      dbcom - 2007-09-14

      Yes, I would be interested. Tried sending the zip file to your SF account, but the zip and email was rejected by the server. Let me know how I might contact you alternatively.

      Thanks,
      dbcom

       
      • TNTEverett

        TNTEverett - 2007-09-14

        Send an email without the attachment and I will reply with my email address. 

         
    • squrler

      squrler - 2009-02-14

      I have been trying to get this to work but I haven't been successful so far. Could anyone please help me out?

      I have added:

      if (validateCheckBox('field_14','fieldBox_14','checkbox',1) == false)
      retVal=false;
      if (validateField('field_14','fieldBox_14','checkbox',1) == false) 
      retVal=false;

      to the end of form.html, and:

                      function validateCheckBox(fieldId, fieldBoxId, fieldType, required)
                      {
                          if(fieldType == 'checkbox') {
                              fieldBox = document.getElementById(fieldBoxId);
                              if(required == 1) {
                                  myfieldId = fieldId+"_option_1";
                                  fieldObj = document.getElementById(myfieldId);
                                  if(fieldObj.checked == 1) {
                                      myfieldId = fieldId+"_option_1";
                                      fieldObj = document.getElementById(myfieldId);
                                      fieldObj.setAttribute("class","mainForm");
                                      fieldObj.setAttribute("className","mainForm");
                                      return true;
                                  } else {
                                      fieldObj.setAttribute("class","mainFormError");
                                      fieldObj.setAttribute("className","mainFormError");
                                      }
                              fieldObj.focus();
                              return false;
                              }
                          }
                      }

      to the beginning of form.html.

      This is the code for the checkbox:

      <li class="mainForm" id="fieldBox_14">
                          <label class="formFieldQuestion">I accept the terms of this agreement&nbsp;*</label><span><input class=mainForm type=checkbox name=field_14[] id=field_14_option_1 value="yes" /><label class=formFieldOption for="field_14_option_1">yes</label></span></li>

      It doesn't seem to work! Also: processor.php gives an error when you hit confirm:

      Notice: Undefined index: field_14 in /my_domain/public_html/preorder/processor.php on line 15

      Could someone please help me out? I'm so close but I just can't figure out what's going wrong here...

       
      • TNTEverett

        TNTEverett - 2009-02-16

        I have done this before so I know what I have works.  If you are still having trouble send me a zip of your form so I can debug what you have.  If it's not just a simple tweak I can add in what I have done in the past and send it back to you. 

         
    • squrler

      squrler - 2009-02-21

      I managed to make it work. Turned out I pasted the javascript code one { too early. Yeah, that easily breaks things. Thanks for your time!!

       

Log in to post a comment.