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

    New to MODx and have added an eForm snippet to my site. I have created 2 template variables which I am looking to use as the values in 2 radio buttons on the form. I have inserted the template variables in the Form Chunk i.e

    <input type="radio" name="FormAnswer" value="[*Form_Answer1*]" eform="Form Answer::1" /> [*Form_Answer1*]

    When I view the form the value of TV is there in the radio button value (after checking the HTML source), but when I submit the form, I get the error message - Form Answer » Incorrect value

    If I substitute the TV placeholder with ordinary text - it works fine.

    Am I going down the right track? I am using TV’s so I don’t have to change the form itself whenever new values are needed for the radio buttons. I have trawled through the forums but I am sure that the answer is out there!!!

    MODx version 1.0.5
    IIS 6.0
    PHP Version 5.2.0

    Thanks in advance!!! huh
      • 4310
      • 2,310 Posts
      Don’t know about the TV values but with radio options, selects or checkboxes the format is something like :
      <input type="radio" name="FormAnswer[]" value="[*Form_Answer1*]" eform="Form Answer::1" /> [*Form_Answer1*]
      <input type="radio" name="FormAnswer[]" value="[*Form_Answer2*]" /> [*Form_Answer2*]

      You only ask eForm to validate the first one because it’s going to be an array containing all the values.
        • 23491 ☆ A M B ☆
        • 1,056 Posts
        Quote from: paraicc at Feb 24, 2011, 11:40 AM

        <input type="radio" name="FormAnswer" value="[*Form_Answer1*]" eform="Form Answer::1" /> [*Form_Answer1*]

        When I view the form the value of TV is there in the radio button value (after checking the HTML source), but when I submit the form, I get the error message - Form Answer » Incorrect value

        @paraicc,

        This should be achievable, unfortunately not "out of the box". eForm can be a bit picky regarding it's "pre-parsed" template values, and unfortunately the TVs TRUE values aren't getting set until AFTER the MODx parser has parsed them. eForm sees this change of value (pre-parsed template vs. post-MODx parsed form submit) as part of it's built in security, and therefore will not allow it.

        One way to fix this is to directly manipulate $modx->chunkCache['your_eform_template_chunk'] via a custom snippet/plugin BEFORE making your eForm snippet call. In otherwords, if you ensure your eForm template (chunk) contains all expected (parsed) values before calling eForm, you won't run into any issues and can still use TVs.

        It may take a good working knowledge of eForm + MODx API to accomplish this, but its definitely do-able. smiley [ed. note: pixelchutes last edited this post 15 years ago.]
          Mike Reid - www.pixelchutes.com
          MODx Ambassador / Contributor
          [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
          ________________________________
          Where every pixel matters.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Yes, you would best solve this by using eForm’s &eFormOnBeforeFormMerge event and a snippet with a function to fetch this value and add it to the $fields array as an ordinary eForm placeholder. Something like this to use [+Form_Answer1+] placeholder tags in the form:
          <?php
          function setTv(&$fields) {
            $fields['Form_Answer1'] = $modx->getTemplateVar('Form_Answer1');
            return true;
          }
          return;
          ?>
          

          And specify the event in the snippet call
          [!eForm? ... &eFormOnBeforeFormMerge=`setTv` &runSnippet=`snippetName`!]

            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
            • 22672
            • 4 Posts
            Thanks all. Will get to work on it asap and get back to you. Many hands make light work!!!
              • 15083
              • 697 Posts
              Quote from: sottwell at Feb 25, 2011, 01:06 AM

              Yes, you would best solve this by using eForm’s &eFormOnBeforeFormMerge event and a snippet with a function to fetch this value and add it to the $fields array as an ordinary eForm placeholder. Something like this to use [+Form_Answer1+] placeholder tags in the form:

              Tried this as you suggested. Just get a white screen.
              The snippet has been created, and the setTv function also. Here is the call:

              [!eForm? &amp;formid=`SS1Form` &amp;subject=`mysubject`
              &amp;to=`[email protected]` &amp;ccsender=`1` &amp;tpl=`SS1Form`
              &amp;report=`SS1FormReport` &amp;thankyou=`SS1FormThanks`
              &amp;invalidClass=`invalidValue` &amp;requiredClass=`requiredValue`
              &amp;vericode=`1` &amp;cssStyle=`ContactStyles` &amp;eFormOnBeforeFormMerge=`setTv` &amp;runSnippet=`check_TV` !]

              any ideas what might be causing the error. I have rules out a syntax error, as I blanked the snippet to ensure this was not the case.