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

    I have a quick question regarding the eForm Snippet.
    Is it possible to create sub categories and email association within a same form?
    Here’s a quick example:

    FORM 1 ----

    Dropdown 1

    > General Inquiry
    [email protected]

    > Customer Support
    [email protected]

    > Other
    [email protected]


    Dropdown 2 (within same form)

    > Product 1
    [email protected], [email protected]

    > Product 2
    [email protected]

    > Product 3
    [email protected], [email protected]

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Combining the values of the two select drop-downs would need a custom snippet-with-function to modify the $fields[’to’] value using eForm’s &eFormOnBeforeMailSent event. See the eForm documentation at assets/snippets/eform/docs/eform_example_events.htm for an example of using such a 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
        • 7188
        • 26 Posts
        Thanks for pointing this example Susan.

        I really have a hard time wrapping my head around the snippet call.
        This is how my current form works and the snippet call I made.

        [+validationmessage+]

        <form method="post" action="[~[*id*]~]" id="support-form">
        <p><label for="requestType">Request Type*</label>
        <select name="requestType" id="requestType" eform="Request Type::1">
        <option value="1">General Inquiry</option>
        <option value="2">Customer Support</option>
        </select></p>
        <p><label for="firstName">First Name*</label><input name="firstName" id="firstName" type="text" class="txt" eform="First Name:string:1" /></p>
        <p><label for="lastName">Last Name*</label><input name="lastName" id="lastName" type="text" class="txt" eform="Last Name:string:1" /></p>
        <p><label for="company">Company</label><input name="company" id="company" type="text" class="txt" /></p>
        <p><label for="email">Email Address*</label><input name="email" id="email" type="text" class="txt" eform="Email Address:email:1" /></p>
        <p><label for="phone1">Telephone*</label><input name="phone1" id="phone1" type="text" maxlength="3" class="txt-phone1" eform="Area Code::1::#REGEX /[0-9]{3}/" /> - <input name="phone2" id="phone2" type="text" maxlength="3" class="txt-phone2" eform="First 3 Telephone digits::1::#REGEX /[0-9]{3}/" /> - <input name="phone3" id="phone3" type="text" maxlength="4" class="txt-phone4" eform="Last 4 Telephone digits::1::#REGEX /[0-9]{4}/" />&nbsp;&nbsp;ext. <input name="phone4" id="phone4" type="text" class="txt-phone4" /></p>
        <p><label for="websiteUrl">Website URL</label><input name="websiteUrl" id="websiteUrl" type="text" class="txt" /></p>
        <p><label for="product">Product*</label>
        <select name="product" id="product" eform="Product::1">
        <option value="Product 1">Product 1</option>
        <option value="Product 2">Product 2</option>
        <option value="Product 3">Product 3</option>
        <option value="Product 4">Product 4</option>
        <option value="Product 5">Product 5</option>
        <option value="Product 6">Product 6</option>
        </select></p>
        <p><label for="comments">Comments</label><textarea name="comments" id="comments"></textarea></p>
        <p><label>&nbsp;</label><input type="submit" value="Submit" /></p>
        </form>

        <p class="footnote">Required fields are denoted by (*).</p>


        The Snippet Call
        -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        [!eForm?
        &formid=`support-form`
        &subject=`Customer and Technical Support Form Submission`
        &to=`[email protected], [email protected]`
        &tpl=`support-form`
        &report=`support-form-report`
        &thankyou=`support-form-thankyou`
        &mailselector=`requestType`!]


        ------ Form 1
        > General Inquiry
        [email protected]

        > Customer Support
        [email protected]


        ------ Form 2 (currently no email associated)
        > Product 1

        > Product 2

        > Product 3

        > Product 4

        > Product 5

        > Product 6



        There are some change requests since I first posted to my form earlier.
        Here’s how I need to have it modified:

        -----
        Dropdown 1
        -----

        > General Inquiry
        [email protected]

        > Customer Support
        [email protected]

        > Other
        [email protected]


        -----
        Dropdown 2 (within same form)
        -----

        > Product 1
        [email protected]

        > Product 2
        [email protected]

        > Product 3
        [email protected]

        > Product 4
        [email protected], [email protected]

        > Product 5
        [email protected]

        > Product 6
        [email protected]


        Could you please tell me how the snippet should be written at this point?


          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You’ll need a new snippet (it must be called before the eForm snippet call so that its function is available within PHP to the eForm code) with a function. This function will have access to all the values eForm has in the $fields array. It’s passed to your function as &$fields, which means you’ll be modifying the array itself and not a copy of it. Any changes or additions you make to the array will be used by eForm.

          eForm has already gathered the POST data (what the user posted, including the selections made from the drop-downs). It also has the $fields[’to’] item, taken from your snippet call (or the default, if you don’t have it in the snippet call).

          Your function will need to get the $fields values from the two drop-down selections, join them into one comma-delimited string, then replace the $fields[’to’] item with that string. End the function with a "return true;" statement, add the function name to the &eFormOnBeforeMailSent parameter in the snippet call, and you’re ready to go.

          You can see another example of this in my site, login info to my Manager is in my signature. Go to the Chunks, and check the Contact category of chunks; the snippet call is in the setContactForm chunk. Then see Snippets, the Forms category, for my extra eForm snippets (I use two in my contact form).
            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
            • 7188
            • 26 Posts
            Susan thanks for pointing out your example...

            I’m however completely lost when it comes to implementing such a feature.

            Could you or would your recommend some to help me out with this?
              • 7188
              • 26 Posts
              Hi Susan, just doing a quick follow up.

              I haven’t been able to pull this off on my own with my current knowledge level...
              Can you please recommend someone who might be able to help out?


                • 7188
                • 26 Posts
                I still haven’t been able to find a solution for this.
                Did anyone work with eForm and had to include 2 dropdown fields before by chance?
                Your help would be very appreciated!