We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18878
    • 210 Posts
    Hello,

    My snippet call looks like this (almost the same as the default Modx installation):

    [!eForm? &formid=`ContactForm` &subject=`[+subject+]` &to=`[email protected]` &ccsender=`1` &tpl=`ContactForm` &report=`ContactFormReport` &invalidClass=`invalidValue` &requiredClass=`requiredValue` &cssStyle=`ContactStyles` &gotoid=`46` !]

    I am making some little modifications to the ContactFormReport chunk which is used in the report parameter of eForm. I have added the Site Name [+sname+], so it looks something like this:

    <p>This is a response sent by [+name+] from the website: [+sname+], using the feedback form on the website. </p>

    But when I send the email, the Site Name is blank:

    This is a response sent by John Doe from the website: , using the feedback form on the website.

    Does anybody know why it doesn’t work? (I have tried [(site_name)] and it doesn’t work too).

    Mc
      • 30223
      • 1,010 Posts
      This is because eForm does not automatically import the MODx settings. Placeholders in eForm templates (form, report, etc) are handled by eForm and not by the MODx core. This is a shortcoming of eForm.

      One solution is to "import" the settings you need into the $fields array using an eForm event funtion.

      //<?php
      function eformOnBeforeParseFunction( &$fields, &$templates ){
         global $modx;
         $fields['sname'] = $modx->config['site_name'];
         return true;
      }
      //?>
      


      (I’ve used the eFormOnBeforeFormParse event as an example here. In your case you could also use the eFormOnValidate or the eFormOnBeforeMailSent function I think)

      Read the eform documentation to learn more about the eform events.
        • 18878
        • 210 Posts
        Jelle,

        Thanks for your guidance.

        This is the implemented solution:

        1) I created a snippet called eFormEvent containing the following code:
        <?php
        function importModxSettings ( &$fields )
        {
        global $modx;
        $fields[’sname’] = $modx->config[’site_name’];
        return true;
        }
        ?>


        2) I modified the ContactFormReport chunk and added [+sname+] in the message.

        3) On the Contact Us page, I added the following snippet call before eForm:
        [[eFormEvent]]

        4) I added the following parameter to my eForm call: &eformOnBeforeMailSent=`importModxSettings`

        It works fine!

        Thank you!

        Mc