We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28559
    • 23 Posts
    Ok so I tried to make the subject as descriptive as possible.

    anyway here is what I’m doing. first page has multiple forms with select fields. ( i need multiple forms because the final post has to be in a certain format depending on the type of form ). I’m useing a standard form to send the value to eform Form page where the passed data is filled into hidden inputs. the value of this is dynamically set by a snippet. now if someone were to cause an error in the form the page reloads without the value for the hidden field.

    heres the code I used

    Form 1
    			
    <form action="[~23~]" method="post">
    				<p>
    				<select name="product">
    				<option value="option_1_value">
    				option 1 text</option>
                                    ...
    				</select>
    				<input type="submit" value="Continue" />
    				</p>
    			</form>
    


    page with ID 23 is

    [!eForm? &formid=`FORM_ID` &to=`eMAIL` &tpl=`FORM` &fromname=`[+name+]` &from=`[+email+]` &report=`REPORT` &thankyou=`THANKYOU` &vericode=`0` &subject=`SUBJECT`!]
    


    Form is

    <form method="post" action="[~[*id*]~]">
        <input type="hidden" name="formid" value="FORM_ID" />
    <input type="hidden" name="torunyinfo" value="[[FormProductInfo]]" eform="torunyinfo::1::#REGEX /.*?/" />
    


    Where [[FormProductInfo]] is
    <?php
    $fee=$_POST['product'];
    return $fee;
    ?>
    


    Result first time through the form

    <form method="post" action="A183SBRF.html">
    <input type="hidden" name="formid" value="FORM_ID" />
    <input type="hidden" name="torunyinfo" value="option_1_value" />
    ...

    but upon error the page reloads with this


    <form method="post" action="A183SBRF.html">
    <input type="hidden" name="formid" value="Tournament_registration" />
    <input type="hidden" name="torunyinfo" value="" />
    ...

    any ideas on how to get the value to stay?

    thanks
    SteveO
      • 27376
      • 576 Posts
      eForm does not process snippet information within the template.

      So when eForm takes a look at your template, it will see the value of [tt]torunyinfo[/tt] as "[tt][[FormProductInfo]][/tt]" literally. Behavior is unpredictable.

      For now though, you can’t have any snippets, TVs, or other chunks nested within your form template.
        • 30223
        • 1,010 Posts
        You can use the eFormOnBeforeFormParse event to run the snippet inside the event... Your form template would look something like this:

        <form method="post" action="[~[*id*]~]">
            <input type="hidden" name="formid" value="FORM_ID" />
        <input type="hidden" name="torunyinfo" value="[+phFormProductInfo+]" eform="torunyinfo::1::#REGEX /.*?/" />
        


        and you’d use an event function a bit like this: (store it in a snippet called eformEventFunctions)
        function onBeforeParseFunction( &$fields, &$templates ){
          global $modx;
          $hiddenValue = $modx->runSnippet('FormProductInfo']);
          $templates['tpl'] = str_replace('[+phFormProductInfo+]',$hiddenValue,$templates['tpl']);
          return true;
        }


        And lastly change your snippet cal to this:

        [[eformEventFunctions]]
        [!eForm? &eFormOnBeforeFormParse=`onBeforeParseFunction` ...rest of parmas... !]
        
          • 28559
          • 23 Posts
          Ok so what did I do Wrong?


          I now get the error
          Fatal error: Call to undefined function: onBeforeParseFunction() in /home/mysite/public_html/MySub/assets/snippets/eform/eform.inc.php on line 138

          i checked all my ’ vs ` there all right from what I can tell. also I did notice and change in the function below $hiddenValue = $modx->runSnippet(’FormProductInfo’]); I added a "[" so its like this $hiddenValue = $modx->runSnippet([’FormProductInfo’]);

          any ideas?

          SteveO
            • 30223
            • 1,010 Posts
            Did you put the function in a snippet and then added a call to that snippet in your form document before the eform call?

            By the way the bracket was a typo. It should have been:

            $hiddenValue = $modx->runSnippet('FormProductInfo');
              • 28559
              • 23 Posts
              Thanks TobyL taking the brackets out got me past the first submission. now the same problem still exists that if there is an error in the form it will not replace the hidden field variable.
              any ideas?

              Steve
                • 30223
                • 1,010 Posts
                Set &debug=`3` and review the debug information at each step. You should be able to work out if and what’s going wrong from that. It will print out the html of the form after it is parsed. What does that look like?
                  • 28559
                  • 23 Posts
                  now its completely busted and I didn’t save a backup of what I changed :’( . Maybe I need to try a different approach altogether.....

                  There are about 5 different options for each of 6+ events and each one of those 30 options needs its own unique value basically to send off to a payment gateway.

                  if you can think of anything let me know.

                  thanks
                  Steve


                  Edit...... radio Buttons or check boxes huh??? I wonder if they would work......