Menu

Required radio buttons are not working

Help
duke
2010-11-30
2013-06-03
  • duke

    duke - 2010-11-30

    Hi,

    I have just completed my form just to discover that my required radio buttons don't work. Users can submit the form even if they don't chose any of the options. Why? I have double checked my form in the form creation panel and on every radio button the option "Required?" is marked. Please help.

     
  • TNTEverett

    TNTEverett - 2010-11-30

    You have done everything right.  Radio buttins are not included in validate scripts for the Version 3 Demo.  I have done my own validateRadio function and have included it below.  Put the validateRadio function above the "function validateField(fieldId, fieldBoxId, fieldType, required)" line in the form.html file.  Change the "if (validateField('field_2','fieldBox_2','radio',1) == false)" line in the "function validatePage1() " section at the bottom of the form.html file.  The validateRadio function looks to validate that at least one button in a set is checked.  Note that "'field_2'" is just my example.  You need to modify fields related to your form. 

    function validateRadio(fieldId, fieldBoxId, fieldType, mysize, required) {
      fieldBox = document.getElementById(fieldBoxId);
      if(required == 1) {
        <!- Loop through each radio button to see if any are checked ->
        for( i=1; i<=mysize; i++) {
          myfieldId = fieldId+"_option_"+i;
          fieldObj = document.getElementById(myfieldId);
          <!- If any buttons are checked return every button to non-highlighted state ->
          if(fieldObj.checked == 1) {
            for( j=1; j<=mysize; j++) {
              myfieldId = fieldId+"_option_"+j;
              fieldObj = document.getElementById(myfieldId);
              fieldObj.setAttribute("class","mainForm");
              fieldObj.setAttribute("className","mainForm");
            }
            <!- If any button is checked return true condition ->
            return true;
          <!- If no buttons are checked return every button to highlighted state ->
          } else {
            fieldObj.setAttribute("class","mainFormError");
            fieldObj.setAttribute("className","mainFormError");
          }
        }
        <!- If no buttons are checked return false condition ->
        fieldObj.focus();
        return false;
      }
    }

    if (validateRadio('field_3','fieldBox_3','radio',4,1) == false)

    The extra field value "4" is the size of the set of radio buttons.  If you have only one option button, the value is "1", if the number of optional radio buttons is "5" then this value is "5".

     
  • duke

    duke - 2010-11-30

    Thanks, this seems to be working! Unfortunately, another problem came out. I started having this error and the script doesn't want to send mails anymore:
    Warning: mail() : SMTP server response: 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1)

    The strange thing is that I get this error even when completing the unmodified PHP form (the one which I downloaded when I completed building my form in the form creation panel)

     
  • TNTEverett

    TNTEverett - 2010-11-30

    I'm not sure I can help you with this error. 
    You need to report this to your web host tech support stating that this error comes from a PHP script using the mail() function.  PHP is a server side scripting language and should execute commends under your account and therefore shold have access to the server sendmail functions. 

     
  • gee em

    gee em - 2010-12-17

    In my case your solution doesn't work properly. The radio buttons are marked as required, but you can submit the form.

    Any ideas?

    Thanks
    Martin

     
  • TNTEverett

    TNTEverett - 2010-12-17

    My idea would be that you made some error in implementing the change.

     
  • gee em

    gee em - 2011-01-06

    The form is now working as expected. I had some errors in the source code (forgot the "return false;" statements and an error not concerning the radio buttons).
    Thanks for your help tnteveret1!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.