We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21025
    • 6 Posts
    Hi everyone,

    I’m trying to use FormIt to run a basic quiz. All it needs to do is allow the user to select various radio button options and then output the results to a printable "results" page. I’ve read through all of the posts about the problems people were having with checkboxes, but haven’t been able to apply any of the advice to my problem. The validation and redirect works, but the values are always blank on the results page. I’ve tested this in every possible browser after clearing the cache multiple times. Here’s my code..

    [[!FormIt? &hooks=`redirect` &store=`1` &redirectTo=`21` &validate=`one:required, two:required, three:required, four:required, five:required`]] 
    <div class="quiz">
    <form action="[[~[[*id]]]]" method="post">
    <ul>
    <li class="clearfix"><div><span class="num">1</span>How often do your eyes feel dry?</div>
    <input type="hidden" name="one[]" value=""> 
     <label class="label_radio" for="1"><input type="radio" id="1" name="one[]" value="never" [[!+fi.one:FormItIsChecked=`never`]] > Never</label>
     <label class="label_radio" for="2"><input type="radio" id="2" name="one[]" value="sometimes" [[!+fi.one:FormItIsChecked=`sometimes`]] > Sometimes</label>
     <label class="label_radio" for="3"><input type="radio" id="3" name="one[]" value="most" [[!+fi.one:FormItIsChecked=`most`]] > Most of the time</label>
     <label class="label_radio" for="4"><input type="radio" id="4" name="one[]" value="always" [[!+fi.one:FormItIsChecked=`always`]] > Always</label>
     <span class="error">[[!+fi.error.one]]</span>
    </li>
    
    <li class="clearfix"><div><span class="num">2</span>How often do your eyes feel gritty or as if there is 'something' in your eye?</div>
    <input type="hidden" name="two[]" value=""> 
     <label class="label_radio" for="5"><input type="radio" id="5" name="two[]" value="never" [[!+fi.two:FormItIsChecked=`never`]] > Never</label>
     <label class="label_radio" for="6"><input type="radio" id="6" name="two[]" value="sometimes" [[!+fi.two:FormItIsChecked=`sometimes`]] > Sometimes</label>
     <label class="label_radio" for="7"><input type="radio" id="7" name="two[]" value="most" [[!+fi.two:FormItIsChecked=`most`]] > Most of the time</label>
     <label class="label_radio" for="8"><input type="radio" id="8" name="two[]" value="always" [[!+fi.two:FormItIsChecked=`always`]] > Always</label>
      <span class="error">[[!+fi.error.two]]</span>
    </li>
    
    <li class="clearfix"><div><span class="num">3</span>How often do your eyes feel painful, sore, or burning?</div>
    <input type="hidden" name="three[]" value=""> 
     <label class="label_radio" for="9"><input type="radio" id="9" name="three[]" value="never" [[!+fi.three:FormItIsChecked=`never`]] > Never</label>
     <label class="label_radio" for="10"><input type="radio" id="10" name="three[]" value="sometimes" [[!+fi.three:FormItIsChecked=`sometimes`]] > Sometimes</label>
     <label class="label_radio" for="11"><input type="radio" id="11" name="three[]" value="most" [[!+fi.three:FormItIsChecked=`most`]] > Most of the time</label>
     <label class="label_radio" for="12"><input type="radio" id="12" name="three[]" value="always" [[!+fi.three:FormItIsChecked=`always`]] > Always</label>
     <span class="error"> [[!+fi.error.three]]</span>
    </li>
    
    <li class="clearfix"><div><span class="num">4</span>How often is your vision blurry or hazy?</div>
    <input type="hidden" name="four[]" value=""> 
     <label class="label_radio" for="13"><input type="radio" id="13" name="four[]" value="never" [[!+fi.four:FormItIsChecked=`never`]] > Never</label>
     <label class="label_radio" for="14"><input type="radio" id="14" name="four[]" value="sometimes" [[!+fi.four:FormItIsChecked=`sometimes`]] > Sometimes</label>
     <label class="label_radio" for="15"><input type="radio" id="15" name="four[]" value="most" [[!+fi.four:FormItIsChecked=`most`]] > Most of the time</label>
     <label class="label_radio" for="16"><input type="radio" id="16" name="four[]" value="always" [[!+fi.four:FormItIsChecked=`always`]] > Always</label>
     <label class="label_radio" for="16b"><input type="radio" id="16b" name="four[]" value="night" [[!+fi.four:FormItIsChecked=`night`]] > Only at night</label>
      <span class="error">[[!+fi.error.four]]</span>
    </li>
    
    <li class="clearfix"><div><span class="num">5</span>How often do you use artificial tears?</div>
    <input type="hidden" name="five[]" value=""> 
     <label class="label_radio" for="17"><input type="radio" id="17" name="five[]" value="never" [[!+fi.five:FormItIsChecked=`never`]] > Never</label>
     <label class="label_radio" for="18"><input type="radio" id="18" name="five[]" value="1to5" [[!+fi.five:FormItIsChecked=`1to5`]] > 1 to 5  times a day</label>
     <label class="label_radio" for="19"><input type="radio" id="19" name="five[]" value="6to10" [[!+fi.five:FormItIsChecked=`6to10`]] > 6 to 10 times a day</label>
     <label class="label_radio" for="20"><input type="radio" id="20" name="five[]" value="morethan10" [[!+fi.five:FormItIsChecked=`morethan10`]] > More than 10 times a day</label>
      <span class="error">[[!+fi.error.five]]</span>
    </li>
    
    <input type="submit" name="submit" value="See Results" class="button right">
    </ul>
    </form>


    I’ve tried to output the results on the results page in every way I could think of, none of which work (different method for every question):

    [[!FormItRetriever? &redirectToOnNotFound=`1`]]  
    <div class="results clearfix">
    <p>1. How often do your eyes feel dry?</p>
    <p class="answer">
    [[+one.0]]
    [[+one.1]]
    [[+one.2]]
    [[+one.3]]
    </p>
    <p>2. How often do your eyes feel gritty or as if there is 'something' in your eye?</p>
    <p class="answer">
    [[+two.never]]
    [[+two.sometimes]]
    [[+two.most]]
    [[+two.always]]
    </p>
    <p>3. How often do your eyes feel painful, sore, or burning?</p>
    <p class="answer">
    [[+fi.three.never]]
    [[+fi.three.sometimes]]
    [[+fi.three.most]]
    [[+fi.three.always]]
    </p>
    <p>4. How often is your vision blurry or hazy?</p>
    <p class="answer">
    [[+fi.four.0]]
    [[+fi.four.1]]
    [[+fi.four.2]]
    [[+fi.four.3]]
    [[+fi.four.4]]
    </p>
    <p>5. How often do you use artificial tears?</p>
    <p class="answer">
    [[+five]]
    </p>
    </div>


    If anyone could give me any help or advice, it would be much appreciated! Thanks a lot!

    MODx Revolution 2.0.7-pl (traditional)
    FormIt 1.5.4 rc1
    PHP version 5.2.14
    MySQL 5.0.91-community



    • Hi there, I struggled with getting a very simple radio box to work but eventually this worked for me:

      In my form:

      <label>Method of despatch: [[!+fi.error.despatch]]</label>
      <input type="radio" name="despatch" value="collect" [[!+fi.despatch:FormItIsChecked=`collect`]]>Collect on night
      <input type="radio" name="despatch" value="post" [[!+fi.despatch:FormItIsChecked=`post`]]>Post

      And in my emailResponse chunk:

      <p>Method of collection:<strong>[[+despatch]]</strong></p>

      I had tried an array but it just didn’t seem to work, then by using the FormItIsChecked it returns only those details that are checked - I haven’t tried it on a long array but it might be as simple as that.

      Let me know how you get on.


        Helen Warner
        Number one pixel!
        Proud to be linked with MODX at Crimson Pixel
        • 14162
        • 67 Posts
        I’m also trying to pass checkbox values to a results page. I’ve got it working fine in the email confirmation, but what is the placeholder syntax for FormItRetriever?

        Form is:

        <input name="foo[]" type="checkbox" id="foo[]" value="bar" [[!+fi.foo:FormItIsChecked=`bar`]] />bar
        <input name="foo[]" type="checkbox" id="foo[]" value="bar2" [[!+fi.foo:FormItIsChecked=`bar2`]] />bar2

        The email return works fine with:

        [[+foo.0]]
        [[+foo.1]]

        But nothing seems to work on a separate page with [!FormItRetriever]]

        Any ideas?