We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37079
    • 5 Posts
    As a complete PHP novice I've been wrestling with this for days now smiley

    I'm building a recruitment website using MODx Evolution 1.0.4 and eForm 1.4.4.6. I have successfully created a form that allows job applicants to send email attachments and it works fine.

    Now I'm trying to auto populate the page heading and a couple of form fields with the Job Title and a Ref. I got this working using a bit of PHP code to pass a querystring parameter from the job page to the form page. This is the code I use to create the page heading for instance:

    <?php
    echo "<h1>Apply For";?> 
    <?php echo $_GET["name"]; ?>
    <?php echo "</h1>";?>
    


    As chunks cannot process PHP, I added all the form HTML along with the above PHP into a snippet and called that snippet using the chunk that is referenced in the usual eForm snippet call.

    The form still displays correctly and it popualtes the heading and form fields as I wanted but now when I hit the submit button to send the email, I get an error message and the email does not get sent.

    I appreciate I might need to provide a bit more info/code for anybody to help here but I'm not sure which bit of code is/could be the problem. If anybody could give me just a nugget of advice I'd be really grateful.
    • There is a proper way to populate eForm fields from an external source, whether from the database or from the GET.

      This involves using a custom function in a snippet, and telling eForm to run that function. The snippet has to be loaded before the eForm snippet, or else you can use a runSnippet parameter in your eForm call.
      eForm? ... &eFormOnBeforeFormMerge=`getGET` &runSnippet=`your-snippet-name`


      The function getGET will fetch the GET values and insert them into the $fields array:
      function getGET(&$fields) {
        $value1 = $_GET['field1'];
        $fields['form-field'] = $value1;
      }
      

      Now when eForm makes your form, the specified fields will contain the GET values.
        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
        • 37079
        • 5 Posts
        Thanks Susan.

        I'm still having trouble getting it to work.

        My eform snippet call now looks like this:

        [!eForm? &formid=`ApplyJob` &subject=`Job Application` &to=`[email protected]` &ccsender=`0` &tpl=`ApplyJob` &report=`ApplyNowReport` &gotoid=`74` &eFormOnBeforeFormMerge=`getGET` &runSnippet=`populateForm` !]
        


        And I created a snippet called populateForm with your code as follows:

        <?php
        function getGET(&$fields) { 
        
        $value1 = $_GET['name1'];
        $fields['jobtitle'] = $value1; 
        }
        ?>


        I changed the value of 'field1' to the parameter name in my querystring which is 'name' and the value of 'form-field' to the name of my form field which is 'jobtitle'

        Is that correct only it creates the form but does not populate the field?

        Appreciate your help with this.
          • 37079
          • 5 Posts
          Sorry Susan. Just realised I made a typo in the code with my parameter name. I only noticed it after re-reading my post.

          Fixed it and it seems to be working now.

          Many thanks for your help.