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

    I’m building an application that relies on eform for form validation. What I’m doing is injecting markup into the DOM with jQuery; the injected markup consists of cloned regions of the form, and so you end up with generated markup like this:

    <input type="text" name="age[]" value="34" />
    <input type="text" name="age[]" value="26" />
    


    eform receives an array for validation once the form is posted, which it appears to convert to a comma separated string for parsing: ’34,26’.

    This works great when the cloned fields have *different* values. The problem I have is that when the second field value is identical to the first (eg ’34’,34’), eform either ignores the value and sets it to ’’, or outputs a validation error if the cloned element is a <select>.

    Does anyone know what would cause this? The eform.inc script is surprisingly complex and I’m at a loss.

    EDIT: this appears to be the same issue as the duplicate field problem reported here:
    http://modxcms.com/forums/index.php?topic=23888.0




      Snippets: GoogleMap | FileDetails | Related Plugin: SSL
      • 14930
      • 70 Posts
      Any progress with this? I’m struggling with the same problem.
        • 29774
        • 386 Posts
        I didn’t solve the problem but I worked around it by adding an incremental index to the cloned field names (eg age_1, age_2) and then recombining the values back into an array just before the data is sent (actually saved to the db in my case).

        Would love to see a real solution to this though.
          Snippets: GoogleMap | FileDetails | Related Plugin: SSL
          • 30223
          • 1,010 Posts
          eForm has never supported form input arrays until recently and then only very limited. The problem is in a bit of very bad and dumb code which filters empty values from any POST array values by a double array_flip(). Don’t know what the author was thinking when he wrote that...

          Replace this bit of code in eform.inc.php (approx line 156)
          //<?php
          # get user post back data
          foreach($_POST as $name => $value){
           if(is_array($value)){
          	//remove empty values
          	$value = array_flip($value);
          	unset($value['']);
          	$fields[$name] = array_flip($value);
           } else
          	$fields[$name]   = stripslashes(($allowhtml || $formats[$name][2]=='html')? $value:$modx->stripTags($value));
          }
          


          with this
          //<?php
          # get user post back data
          foreach($_POST as $name => $value){
           if(is_array($value)){
          	//remove empty values
          	$fields[$name] = array_filter($value,create_function('$v','return (!empty($v));'));
           } else
          	$fields[$name]   = stripslashes(($allowhtml || $formats[$name][2]=='html')? $value:$modx->stripTags($value));
          }
          


          This should fix the disappearing values, however you may run into other issues. eForm simply doesn’t deal well with multiple values for normal text input fields.

          and for teh record,... yes the author of teh offending bit of code was me embarrassed and I’m surprised it hasn’t bitten anyone until now. smiley
            • 29774
            • 386 Posts
            Hi Toby

            thanks for the fix, I’ll give a a go and report back. For what it’s worth I think the author of eform should be congratulated on producing an extremely useful and versatile form processing script; it’s certainly made my life a lot easier recently. Thanks mate smiley.

            Mark

              Snippets: GoogleMap | FileDetails | Related Plugin: SSL
              • 14930
              • 70 Posts
              Thank you, TobyL! That fixed it.

              Also, I agree with therebechips, eForm has made mine easier as well, and I can’t really thank you enough for it! Keep up the good work, friend!