We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1511
    • 144 Posts
    I have eForm 1.4.3 and have a form with a select like this
    <select name="nationality" size="1" eform='Nationality::1:Select a nationality!:#REGEX "\w{3}"' value="[+nationality+]">
             <option value=" ">...</option>
           {{nationalityDropDown}}
    </select>


    No matter what I select, the value is posted, but eForm sets a validation error for this field.

    If I hardcode the selections from the chunk, everything is ok.
    <select name="nationality" size="1" eform='Nationality::1:Select a nationality!:#REGEX "\w{3}"' value="[+nationality+]">
             <option value=" ">...</option>
          <option value="SLO">SLO</option>
          <option value="ITA">ITA</option>
          <option value="AUT">AUT</option>
    </select>


    Have I missed something? Because being able to include chunks would make my code more readable and manageable.
      • 25663 MODX Staff
      • 12,272 Posts
      I ran into the same problem a long time ago. I don’t think you can do that unfortunately right now.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 30223
        • 1,010 Posts
        Yes you can,... well sort off anyway.

        The problem is that the chunk or snippet with the options isn’t evaluated until AFTER eForm has finished parsing. eFom simply doesn’t know about the values yet and as it uses it’s own validation rule for select boxes it throws a validation error.

        The way to do this is to use the eFormOnBeforerParse event to evaluate the options chunk and replace the options in the form during that event. eForm will then parse the values correctly. Have a look through this forum for an example. This issue has arisen and been solved before.

          • 19797
          • 18 Posts
          The trick is to do your own validation. This will remove validation alltogether. Feel free to get a little more creative.

          In the snippet call
          &eFormOnValidate=`customValidation`
          


          In the snippet
          function customValidation(&$fields, &$vMsg, &$rMsg) {
                      $vMsg = array();
                      $rMsg = array();
                      return true;
          }
          
            • 30223
            • 1,010 Posts
            Well now,... that’s a really good suggestion and an excellent example. Sorry to be a bit sarcastic here but why would you use eForm in the first place if you’re just removing the validation all together , or rewrite all of it.
              • 19797
              • 18 Posts
              I didn’t think eForm’s sole purpose was validation. This is just a temporary workaround until the eForm validator can account for dynamic from data. I wasn’t suggesting not doing any validation. Just do your own until eForm is able. Everything is available in the fields array.
                • 7455
                • 2,204 Posts
                is there already a way to populate eForm dynamically?
                I like to use ditto to populate a dropdownlist with event dates my template looks like this:
                <select class="formselect" name="thisshowdate" eform="For this show::0"/>
                [[Ditto? &startID=`24` &tpl=`agendaform_tpl` &multiLevel=`1`&filter=`vol,yes,7` &language=`nederlands` &total=`99` &sortBy=`unpub_date` &dateFormat=`%d %B %Y` &sortDir=`ASC`  &summarize=`99`]] 
                </select>
                


                and it creates a nice puldownlist, but I get this error: For this show » Incorrect value.

                would be nice to have an extra pars option like eform="For this show:dynamic:0"

                dimmy
                  follow me on twitter: @dimmy01
                  • 30223
                  • 1,010 Posts
                  is there already a way to populate eForm dynamically?
                  I like to use ditto to populate a dropdownlist with event dates my template looks like this:
                  Dimmy, Yes there is and there are several examples in the forums, but you can not use snippet tags inside eform chunks for the simple reason that they are evaluated after eForm has finished executing! As eForm uses the data parsed from the form chunk to validate select fields (and check and radio boxes) dynamically filling these fields needs to happen BEFORE eform parses the form.

                  So in your case you need to use the eFormOnBeforeParseFOrm event and execute your ditto call there using $modx->runsnippet()

                  <?php
                  function BeforeFormParseFunction(&$fields, &$templates){
                     global $modx;
                     
                     $ditto_params => array(
                        'startID' => '24',
                        'tpl' => 'agendaform_tpl',
                        'multiLevel' => '1'
                        'filter' => 'vol,yes,7',
                        'language' => 'nederlands',
                        'total' => '99',
                        'sortBy' => 'unpub_date',
                        'dateFormat' => '%d %B %Y',
                        'sortDir' => 'ASC' ,
                        'summarize' => '99'
                     );
                     
                     $templates['tpl'] = str_replace('[+ditto_placeholder+]',$modx->runsnippet('Ditto',$ditto_params),$templates['tpl']);
                     
                     return true;
                  }
                  
                  ?>
                  


                  Your template chunk would then contain this:
                  <select class="formselect" name="thisshowdate" eform="For this show::0"/>
                  <option value=''> </option> <!-- In case you want to leave option of not selecting anything -->
                  [+ditto_placeholder+]
                  </select>
                  


                  and you add &eFormOnBeforeParse=`BeforeFormParseFunction` to your eForm snippet call.
                    • 4707
                    • 73 Posts
                    TobyL, thanks for your guidance in the forums. I managed to create a select from the database for my contact form.

                    I still got some questions though. Is there any difference between creating the dynamic content in the eFormOnBeforeParseForm event versus creating it in a snippet call (&tpl=`MyFormBuilderSnippet`)? Also, is there a way to call the "MyFormBuilderSnippet" with parameters?
                      • 7455
                      • 2,204 Posts
                      nice work,

                      after a small debugging session
                      i got it working (event to call is eFormOnBeforeFormParse, $ditto_params => array needs to be $ditto_params = array and ’multiLevel’ => ’1’ was missing a ,

                      I learned something new again today. where do I find the parameters to use in the plugins like &$fields, &$templates. and what they do.

                      Thank you for your help.

                      Dimmy
                        follow me on twitter: @dimmy01