We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31178
    • 128 Posts
    After upgrading to the 0.9.6.3 of MODx I had a site where pre-checked checkboxes where not being honoured using checked="checked" .
    I followed this topic:
    http://modxcms.com/forums/index.php/topic,32896.0.html

    to get the latest eForm version (1.4.4.6) and I am now getting a slightly different issue. Yes the checkboxes are now selecting, but if I uncheck a checkbox and submit the form and it for example correctly fails to validate because of another field that is required then the checkbox is incorrectly rechecked because line #827 in the code is always true.

    //if no postback, retain any checked values
    if(!$isPostBack && !empty($tagAttributes['checked'])) $fields[$name][]=stripTagQuotes($tagAttributes['value']);


    Looking in the eform.inc.php code I see a line around line #684 which sets $isPostBack
    # check if postback mode
    $isPostBack	= (count($_POST)>0 && $modx->event->params['formid']==$_POST['formid'] )? 1:0;


    now this always seems to return 0 because event->params[’formid’] does not exist.

    the old eForm version did not have this formid check:
    $isPostBack	= (count($_POST)>0)? 1:0;


    I have read another topic: http://modxcms.com/forums/index.php/topic,32946.0.html
    relating to $modx->event but can’t really see what is going on as I am not using any custom validation.


    [update] - In my simple test example I had not defined the thankyou chunk which I had in the snippet call. Creating that fixed the example.
      • 31178
      • 128 Posts
      I have followed this further and if I create an eForm template as a snippet and not a chunk then I get the postback always coming back as false at line 685 in eform.inc.php ??

      My template (test2) has been simplified (I realize this particular template could be stored as a chunk):
      <?php
      ?>
      
      [+validationmessage+]
      <form method="post" action="[~[*id*]~]" id="test_1">
          <p>text<input type="text" name="fullname" size="30" maxlength="60" eform="Name::1" /></p>
          <p>radio<input name="rad" id="rad" type="checkbox" value="yes" checked="checked" /></p>
          <p><input class="verify" type="submit" name="Submit" value="Send"></p>
      </form>
      
      <?php
      ?>


      The eForm call is:
      [!eForm? &debug=`1` &formid=`test_1` &tpl=`test2` &noemail=`1` !]

      if you run the page and uncheck the checkbox and submit the form it returns asking for the text to be completed (as expected), but the checkbox is rechecked.
      This is due to line 685 in eform.inc.php always returning 0, which in turn prevents line 827 being true:
      if(!$isPostBack && !empty($tagAttributes['checked'])) $fields[$name][]=stripTagQuotes($tagAttributes['value']);

      and hence not unchecking the checkbox after a failed validation postback.... it works fine as a chunk.

      I added a line after 685 to check this isPostBack value:
      echo '$isPostBack:'.$isPostBack;
        • 25663 MODX Staff
        • 12,272 Posts
        Please file a bug for this in JIRA. Seems like an improvement is definitely warranted:
        http://bugs.modxcms.com/
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 31178
          • 128 Posts
          Quote from: rthrash at Jul 18, 2009, 01:53 PM

          Please file a bug for this in JIRA. Seems like an improvement is definitely warranted:
          http://bugs.modxcms.com/

          done: ADDON-53
          Feeling guilty about the number of bugs I’m filing at the moment wink
            • 33337
            • 3,975 Posts
            no need to feel guilty when you are helping... tongue
              Zaigham R - MODX Professional | Skype | Email | Twitter

              Digging the interwebs for #MODX gems and bringing it to you. modx.link