We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3349
    • 126 Posts
    Hi

    I have had a look through the forums and and im still baffled.

    Put simply, I have an eForm snippet call: (n.b - im using YAMS)

    [!eForm? &language=`(yams_mname)` &formid=`bookingForm_(yams_id)` &to=`` &from=`((email))` &tpl=`eBookingForm_(yams_id)` &report=`eBookingReport_(yams_id)` &thankyou=`eBookingThanks_(yams_id)` &subject=`Booking Enquiry`!]


    In my form tpl eBookingForm_en I have a text field that pulls the pagetitle as the value: (this works fine and the field is populated with the actual pagetitle)

    <div class="field">
    		<input class="destination" name="destination" value="[*pagetitle*]" type="text" disabled="disabled" />
    </div>


    and then in my eBookingReport_en TPL I have:

    <p>This is a booking enquiry sent by [+name+] for [+destination+]</p>


    Problem is I thought the [+destination+] placeholder would pull through the pagetitle value but it actually displays the word "[*pagetitle*]"

    What have I done wrong???

    Thanks
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      That is because actually eForm did put [*pagetitle*] as the value of the field in the form, but MODx converted it to the value of [*pagetitle*] as it continued processing the resource. Since the report is not being processed by the MODx parser, it doesn’t get converted. You’ll need to use a function and the &eFormOnBeforeMailSent event to set the $fields[’destination’] to the POST value.
        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
        • 3349
        • 126 Posts
        Is there any support/help on using functions?

        I have no experience and unsure where to start

        Thanks
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Create a new snippet. Put this in it.
          function setDestination( &$fields ){
              $fields['destination']=$_POST['destination'];
              return true;
          }
          

          Add this to your eForm snippet parameters.
          &eformOnBeforeMailSent=`setDestination`

          From this point you have two options. Put your new snippet’s tags before the eForm snippet tags, or you can add another parameter to the eForm snippet to have it run the function internally (if you’re using eForm 1.4.4 or later. The snippet name does not have to be the same as the function name; in fact a snippet can hold more than one function if you want to use more than one eForm event. The point is that the function needs to be available to the eForm snippet at some point before the eForm snippet tries to use it. Calling it as a snippet before the eForm snippet is called does this since MODx will load it when it comes to the snippet’s tags. Using the new eForm parameter will have eForm itself run the snippet internally, loading the function.
          &runSnippet=`name-of-snippet`
            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
            • 3349
            • 126 Posts
            Hi Susan

            Thanks for the help... strange things happening now...

            I’ve setup the snippet and applied the new parameters to the eFrom snippet but when I click the submit button - if the page doesn’t load blank - no vlaue comes through in the email. But on most occassions the &eFormOnBeforeMailSent is causing loading issues?

            Here is my snippet call

            [!eForm? &language=`(yams_mname)` &runSnippet=`getDestination` &eFormOnBeforeMailSent=`setDestination` &formid=`bookingForm_(yams_id)` &to=`` &from=`((email))` &tpl=`eBookingForm_(yams_id)` &report=`eBookingReport_(yams_id)` &thankyou=`eBookingThanks_(yams_id)` &subject=`Booking Enquiry`!]


            and my getDestination snippet

            <?php
            function setDestination( &$fields ){
                $fields['destination']=$_POST['destination'];
                return true;
            }
            ?>


            Any ideas?
              • 3349
              • 126 Posts
              Smallish update...

              The parameter &runSnippet causes the page to load blank (this is even before the submit button is pressed) when you first visit the page it is blank? Removing the this parameter and the page loads fine.

              I also tried calling the snippet [[getDestination]] outside the eForm snippet but again the page loads blank?

              Not sure what would cause this?
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                What is the version of your eForm?
                  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
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  The snippet will need to be called uncached [!snippetName!] to work.
                    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
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Sounds like there is an error in the snippet code. Does the snippet code have a single set of <?php ... ?> tags surrounding it? If you just copy/pasted from the forum post, it may have a doubled set of PHP tags.
                      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
                      • 9995
                      • 1,613 Posts
                      [move]Susan is spamming[/move]
                        Evolution user, I like the back-end speed and simplicity smiley