We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40088
    • 708 Posts
    I recently had to add 3 radio buttons to a working form and now it won't submit. At one point I was able to get the form to work but the value of the selected radio button was not being passed to the success email. Not sure what I did wrong.

    The form:

    [[!FormIt?
    &hooks=`spam,email,redirect`
    &emailTpl=`advertiseEmail`
    &emailSubject=`Advertising Inquiry`
    &emailTo=`[email protected]`
    &store=`1`
    &redirectTo=`50`
    &submitVar=`adSubmit`
    &validate=`first:required, last:required, print:required, online:required, both:required`
    ]]
    [[!+fi.error_message:notempty=`<p class="error">[[!+fi.error_message]]</p>`]]
    
    <form action="[[~[[*id]]]]" method="post" id="advertiseForm">
    <input type="hidden" name="nospam:blank" value="" />
    
    <fieldset>
    <label class="floatLt" for="first">
    First:<br />
    <span class="error">[[!+fi.error.first]]</span>
    </label>
    <input type="text" name="first" id="first" value="[[!+fi.first]]" class="" />
    
    <label class="floatLt" for="last">
    Last:<br />
    <span class="error">[[!+fi.error.last]]</span>
    </label>
    <input type="text" name="last" id="last" value="[[!+fi.last]]" />
    </fieldset>
    
    <fieldset>
    <label class="floatLt" for="advertising">
    Form of Advertising:<br />
    <span class="error">[[!+fi.error.advertising]]</span>
    </label>
    <input type="hidden" name="advertising[]" value="" />
    <input type="radio" name="advertising[]" id="print" value="[[!+fi.print]]" [[!+fi.color:FormItIsChecked=`blue`]] > Print
    <input type="radio" name="advertising[]" id="online" value="[[!+fi.online]]" [[!+fi.color:FormItIsChecked=`red`]] > Online
    <input type="radio" name="advertising[]" id="both" value="[[!+fi.both]]" [[!+fi.color:FormItIsChecked=`green`]] > Both
    </fieldset>
    
    <fieldset>
    <label class="floatLt" for="comments">
    Comments/Questions:
    </label>
    <textarea cols="30" rows="6" class="floatLt"></textarea>
    </fieldset>
    
    <input type="submit" name="adSubmit" value="Send" id="adSubmit" class="submitButton bttn" />
    </form>
      Todd
    • You need to fix the radio buttons to this:

      <input type="radio" name="advertising[]" id="print" value="Print" [[!+fi.advertising:FormItIsChecked=`print`]]> Print
      <input type="radio" name="advertising[]" id="online" value="Online" [[!+fi.advertising:FormItIsChecked=`online`]]> Online
      <input type="radio" name="advertising[]" id="both" value="Both" [[!+fi.advertising:FormItIsChecked=`both`]]> Both
      
      


      Make sure you remove the hidden input field with the advertising value.

      That should fix it, good luck,
        Benjamin Marte
        Interactive Media Developer
        Follow Me on Twitter | Visit my site | Learn MODX
        • 4172
        • 5,888 Posts
        you will also need to change the validation to:

        &validate=`first:required, last:required, advertising:required`


        and there is no reason to send advertising as an array. This should be good:

        <input type="radio" name="advertising" id="print" value="print" [[!+fi.advertising:FormItIsChecked=`print`]]> Print
        <input type="radio" name="advertising" id="online" value="online" [[!+fi.advertising:FormItIsChecked=`online`]]> Online
        <input type="radio" name="advertising" id="both" value="both" [[!+fi.advertising:FormItIsChecked=`both`]]> Both
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
        • @Bruno if this is true then we need to get the docs updated because they recommend an array.

          FormIt Handling Selects and Radios

          @todd.b can you post back if it works or not so I can let ScottBorys know so he can update the docs this friday.

          Thanks.
            Benjamin Marte
            Interactive Media Developer
            Follow Me on Twitter | Visit my site | Learn MODX
            • 40088
            • 708 Posts
            Quote from: benmarte at Oct 17, 2012, 08:14 PM
            @Bruno if this is true then we need to get the docs updated because they recommend an array.

            FormIt Handling Selects and Radios

            @todd.b can you post back if it works or not so I can let ScottBorys know so he can update the docs this friday.

            Thanks.

            Thanks guys. I will make the changes right now and post back a.s.a.p. Btw, I followed the docs with regard to the array.

            Be back shortly.
              Todd
              • 40088
              • 708 Posts
              @benmarte I tried your suggestion but the form would still not submit.

              @Bruno17 Your suggestion worked insofar that the form did submit (with and without the hidden field) but unfortunately no value for the selected radio button was passed to the success email.
                Todd
              • Multiple checkboxes and multi-select dropdowns need to be an array, but since only one radio button of a set can be selected it doesn't need to be an array.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 40088
                  • 708 Posts
                  Got it working! Thank you both very much.

                  Here's what I ended up with (stripped down) and without the hidden field:

                  [[!FormIt?
                  &hooks=`spam,email,redirect`
                  &emailTpl=`advertiseEmail`
                  &emailSubject=`Advertising Inquiry`
                  &emailTo=`[email protected]`
                  &store=`1`
                  &redirectTo=`50`
                  &submitVar=`adSubmit`
                  &validate=`first:required, last:required, advertising:required`
                  ]]
                  [[!+fi.error_message:notempty=`<p class="error">[[!+fi.error_message]]</p>`]]
                  
                  <fieldset>
                  <label for="advertising">
                  Form of Advertising:
                  <span class="error">[[!+fi.error.advertising]]</span>
                  </label>
                  <input type="radio" name="advertising[]" id="print" value="Print" [[!+fi.advertising:FormItIsChecked=`print`]]> Print
                  <input type="radio" name="advertising[]" id="online" value="Online" [[!+fi.advertising:FormItIsChecked=`online`]]> Online
                  <input type="radio" name="advertising[]" id="both" value="Both" [[!+fi.advertising:FormItIsChecked=`both`]]> Both
                  </fieldset>
                  [ed. note: todd.b last edited this post 11 years, 6 months ago.]
                    Todd
                    • 40088
                    • 708 Posts
                    One last thing ...

                    The textarea field "comments" (which is not a required field) is not passing the content to the success email. Here's what I see in the email:

                    Comments:
                    [[+comments]]


                    And the form:

                    <fieldset>
                    <label for="comments">
                    Comments/Questions:
                    </label>
                    <textarea cols="30" rows="6" name="comments" id="comments" value="[[!+fi.comments]]" >
                    </fieldset>
                      Todd
                      • 40088
                      • 708 Posts
                      Disregard the textarea problem. I deleted the modx cache and it seems to be working.
                        Todd