We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10481
    • 9 Posts
    Hi,
    I want to use a snippet as the &automessage in order to customize the message depending on the choices made. I tried the following:

    <?php
    echo "[+prog+]\n";
    $prog = [+prog+];   \\ syntax error, unexpected '['...
    if ($prog == 1){
      echo "choice 1\n";}
    elseif ($prog == 2){
      echo "choice 2\n";}
    else {
      echo "choice ?\n";}
    ?>


    However
    $prog = [+prog+]
    gives a << syntax error, unexpected '[' >>
    Replacing it with
    $prog = "[+prog+]"
    eliminates the error, but can't match the condition in the if statement.

    Forcing everything to a string and comparing strings did not help

    <?php
    echo "[+prog+]\n";             \\ 2
    $prog = (string)"[+prog+]";
    if ($prog == (string)1){
      echo "choice 1\n";}
    elseif ($prog == (string)2){
      echo "choice 2\n";}
    else {
      echo "choice ?\n";}          \\ choice ?
    ?>


    Nor forcing everything to an integer.

    What am I doing wrong?
    • Eform doesn't use the modx placeholders[] array, it maintains its own placeholders management and replacement functions. In any case, you can't use tags like that to get a value.

      What you need to do is create a snippet with a function to use the eFormOnMailSent event, and set the appropriate $fields array values. eForm automatically creates the placeholders to be used in your autotext chunk tpls from the values in the $fields array.
        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
        • 10481
        • 9 Posts
        Thanks Susan, finally got it working.

        For completeness here is the gist of what I did...

        The FormTemplate chunk:
        <!-- Begin FormTemplate -->
        <form id="FormID" method="post" action="[~[*id*]~]">
        [+validationmessage+]
        
        <label for="email">Your email: </label>
        <input id="email" name="email" type="text" value="" eform="Email:email:1" />
        
        <input id="prog_1" name="prog" type="radio" value="1" eform="someValidationText::1" />
        <label for="prog_1">Choice 1</label>
        <input id="prog_2" name="prog" type="radio" value="2" eform="someValidationText::1" />
        <label for="prog_2">Choice 2</label>
        
        <p>Please enter the anti spam code below:<br />
        <img src="[+verimageurl+]" alt="verification code" border="1"/></p>
        <p><label for="vericode">code</label>
        <input type="text" name="vericode" size="20" /></p>
        
        <input type="submit" name="submit" value="Submit" />
        </form>
        <!-- End FormTemplate -->

        The eFormFunctions snippet:
        <php?
        function fctOnBeforeMailSent( &$fields ) {
            fct1 ($fields);
            fct2 ($fields);
        }
        
        function fct1( &$fields ) {
            $prog = [+prog+];
            if ($prog == 1){
              $prog_mod == "choice 1";}
            elseif ($prog == 2){
              $prog_mod == "choice 2";}
            else {
              $prog_mod == "choice ?";}
            return true;
        }
        
        function fct1( &$fields ) {
            // some other function if required
            return true;
        }
        return '';
        ?>

        The Report chunk: I want to get the raw data only so I can handle it upon reception.
        <!-- Begin Report -->
        [+email+],[+prog+]
        <!-- End Report -->

        The MessageToSendToClient chunk: Here the data is sent out in a readable form. The called function converts the raw data to something more useful.
        <!-- Begin MessageToSendToClient -->
        <p>You have submitted a form, here is your choice:</p>
        <p>[+prog_mod+]
        <!-- End MessageToSendToClient -->

        The EformCall chunk:
        [!eFormFunctions!]
        [!eForm?
          &tpl=`FormTemplate`
          &formid=`FormID`
          &report=`Report`
          &automessage=`MessageToSendToClient`
          &eFormOnBeforeMailSent=`fctOnBeforeMailSent`
          &to=`[email protected]`
          &from=`[email protected]`
          &fromname=`Sender Ltd.`
          &subject=`You filled a form: here is some feedback.`
          &thankyou=`ThanksChunkToLoadAfterSubmit` 
          &vericode=`1`
        !]
        

        Note using [[]] instead of [!!] failed to work on my system. &protectSubmit=`0` was required since I kept getting a warning message about duplicate entries, even if the data submitted was different.

        In the ressource where the form is to appear, place:
        {{EformCall}}