We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 356
    • 31 Posts
    For last two days I’ve tried to create simple form so my visitors can fill several fields, click "Finish" and get completely filled form to be printed out. I’ve used eForm and mostly happy with my choice smiley but I just can’t do something I really need - I can’t pass results of php code execution in my result page. Version of MODx - 1.02, eForm is from MODx 1.02 (ver. 1.4.4.6).

    I created a page with code:

    [tt][!eForm?
    &formid=`bill`
    &tpl=`eFB_Bill`
    &thankyou=`25`
    &vericode=`0`
    &protectSubmit=`0`
    &noemail=`1` !]
    [/tt]

    and put form’s code to eFB_Bill chunk (which contain something like
    [tt]
    <form action="[~[*id*]~]" id="bill" name="bill" method="post">
    <p style="color: darkred;">[+validationmessage+]</p>
    <input type="text" name="field1name" eform="Field 1 description::1" value="" />
    </form>
    [/tt]
    ). After form is filled with proper values eForm loads content of page with id=25 (which is also pretty simple:
    [tt]
    <p>[+field1name+]</p>
    [/tt]
    ), and display form to be print out.

    But I need to put, say, current date (in general, result of any php code execution, so let it be ’date("Y")’ for our example) into content of ’id=25’ page. Whatever way I tried it it won’t add the php execution result.

    SO the question is: how can I put php code execution result into the eForm result page?

    Thank you in advance for the advice!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You’ll want to use an external snippet to modify eForm’s $fields array; using the onBeforeMailSent event makes this new field available to the mail’s output in the chunk.

      Here’s my getServer snippet, which would roughly correspond to the simple PHP function you want returned:
      function getServer( &$fields ){
          // remote_addr
          $fields['remote_addr']=$_SERVER['REMOTE_ADDR'];
          $fields['remote_host']=$_SERVER['REMOTE_HOST'];
          $fields['user_agent']=$_SERVER['HTTP_USER_AGENT'];
          //return succes
          return true;
      }


      And here’s my page with the snippet calls BEFORE the eForm call.
      [!getServer!]
      [!checkField!]
      <h1>[*longtitle*]</h1>
      [!eForm? &formid=`ContactForm` &tpl=`ContactForm` &report=`ContactReport` &subject=`sottwell.com Contact` &thankyou=`ThankYou` &from=`[+email+]` &fromname=`[+name+]` &replyto=`email` &debug=`1` &eformOnBeforeMailSent=`getServer` &eformOnValidate=`checkField`!]
      


      And here’s my mail output chunk tpl:
      <h3>Contact Input</h3>
      <strong>Name:</strong> [+name+]<br />
      <strong>Email:</strong> [+email+]<br />
      <strong>Message:</strong> [+message+]<br />
      <strong>IP:</strong> [+remote_addr+]<br />
      <strong>Host:</strong> [+remote_host+]<br />
      <strong>User Agent:</strong> [+user_agent+]


      As you can see, now those three extra fields are available to me.

      Check the eForm documentation in the docs directory for more on how to use eForm events and "helper" snippets.
        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
        • 356
        • 31 Posts
        Thank you very much, sottwell, I get the idea. Frankly, you’ve shown me a nice trick, it’ll save me a lot of time!

        Thanks again for such a great support I see from you!