We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8609
    • 607 Posts
    So I have a feeling this isn’t too hard but I’m banging my head against it and would love some help. I’m building a site where I want to add a "Ask About This Product" link to specific pages, and to each item on the ditto page aggregating these resources. The idea is that the when the person clicks on the link it takes them to the contact page where the name of the product is already pre-populated in the subject field.

    I’ve tried different approaches with no luck. Any ideas are welcome

    thanks

      • 26903
      • 1,336 Posts
      You can call Eform with a subject line like
      !eForm? &formid=`ContactForm` &subject=`[+subject+]...`
      could you not change the subject to $_GET and get the name of the product as a parameter from the link?
        Use MODx, or the cat gets it!
        • 3749
        • 24,544 Posts
        There’s probably an easier way, but I would just put a snippet on the product page that saves the product name in a $_SESSION variable. Then, on the form page, put another snippet at the top of the page that gets the $_SESSION variable and sets the appropriate placeholder. Both snippets would return an empty string.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 8609
          • 607 Posts
          Quote from: shamblett at Sep 23, 2010, 08:30 AM

          You can call Eform with a subject line like
          !eForm? &formid=`ContactForm` &subject=`[+subject+]...`
          could you not change the subject to $_GET and get the name of the product as a parameter from the link?

          Thanks, this was my initial thought, but I couldn’t get it to work primarily. You’ve brought me one step closer but I still have to figure out how to get the $_GET in the snippet call. Also wondering if it would work with friendly URLs... hmm, back to the code I go.

          Quote from: BobRay

          There’s probably an easier way, but I would just put a snippet on the product page that saves the product name in a $_SESSION variable. Then, on the form page, put another snippet at the top of the page that gets the $_SESSION variable and sets the appropriate placeholder. Both snippets would return an empty string.

          Thanks Bob, that sounds like workable solution. The only issue I see is on the aggregated page, where all the products are listed with the Ask About This Product on each listing... but it definitely sounds workable. Back into the code.... Thanks!!
            • 16278
            • 928 Posts
            You can get the GET into your field using an eForm event. Here’s what I tried out on the demo site, with a simple text field named subject replacing the drop-down selector:
            <label for="cfSubj">Regarding
            <input name="subject" id="cfSubj" class="text" type="text" eform="Form Subject::1"/></label>
            


            You need a snippet to define the function that eForm will refer to, e.g.
            <?php
            //eFormExtender: functions for eForm events
            function populateSubject(&$fields) {
                   $fields['subject'] = $_REQUEST['Product'];
            }
            return;
            ?>


            Your form page will call this snippet before calling eForm, and eForm will have the parameter &eformOnBeforeFormParse pointing to your function:
            [!eFormExtender!]
            [!eForm? &formid=`ContactForm` &subject=`[+subject+]`
             &eFormOnBeforeFormParse=`populateSubject` 
            &to=`[(emailsender)]` &ccsender=`1` &tpl=`ContactForm` 
            &report=`ContactFormReport` &invalidClass=`invalidValue` 
            &requiredClass=`requiredValue` &cssStyle=`ContactStyles` 
            &gotoid=`46`  !]
            

            Call the page as index.php?id=6&Product=beanies and you have beanies in the subject field.

            I’ve used this approach previously to set up a contact page to generate individualized emails to members of a committee. Looking at the eForm documentation, I was expecting eFormOnBeforeFormMerge to be the hot candidate here, but testing it on my local install (with no mail sender) the field’s value did not seem to be preserved when I got the validation failures back, while eFormOnBeforeFormParse was OK.
            smiley KP

            • Call the page as index.php?id=6&Product=beanies and you have beanies in the subject field.

              How do you "Call the page as" ...? Probably a silly question but unfortunately I need to ask it. And is it the same in a friendly URL environment? [ed. note: intandem last edited this post 12 years, 2 months ago.]