We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 813 ☆ A M B ☆
    • 326 Posts
    Hi everyone,

    I’ve created a member directory that pulls directly from all WebloginPE registrations, with some table filtering and sorting provided by the awesome JQuery DataTables plugin:

    http://kanspra.org/index.php?id=43

    Now, I’d like to take this one step further. As you can see, I’ve added a "checkbox" column, and each checkbox’s value is set for the table row’s corresponding e-mail address. What I want to do is create a way for users of the site to contact whichever people in the list they want, and I think the way to accomplish this is twofold:


    • After the user sorts the table as they see fit, they can put a checkmark next to the people they want to contact, which would add all of these e-mail addresses to a comma-separated list via JQuery (at least I think that’s what I want).
    • Place an eForm snippet on the page. I want this snippet’s &to parameter dynamically filled by whatever people are checkmarked.

    I’m positive this can be done, but I can’t get the necessary JQuery and eForm event (I believe it’s eFormOnBeforeMailSent?) to work at all. I’m still pretty rough with some of this custom stuff, so if I’m approaching it wrong, please let me know. Help, please!!!

    Thanks!
      • 813 ☆ A M B ☆
      • 326 Posts
      I should add that I don’t mind using a second page for the eForm call, if necessary. So maybe they checkmark the people they want, hit a button that says "Send E-mail," and that somehow gathers up all the checked e-mail addresses and uses them as the &to on the subsequent page.
        • 27672
        • 168 Posts
        i am looking to do essentially the same thing, it looks like (from your link) that you were able to get it working... could you please explain how you go this to work??

        thanks so much - at least i now know what i’m looking to do is indeed possible.
          • 813 ☆ A M B ☆
          • 326 Posts
          I’d be glad to help! Let me start by saying that this problem had me confused for weeks. There me be a more elegant way to pull it off (like being able to place the form on the same page as the contact directory), but this way definitely works.

          In addition to eForm, WebLoginPE and a little JQuery, the real magic here was handled by two snippets: eform2session and Session2Placeholders. They aren’t well-documented in the "Extras" section, but here’s a forum thread about them that will help:

          http://modxcms.com/forums/index.php/topic,15350.0.html

          Once you’ve read up on and installed those snippets, here’s my solution:

          1. Create two pages: one for the member directory, and one for the form.
          2. On the member directory page, call the eform2session snippet first, then eForm immediately after. Mine looks like this:

          [[eForm2session]]
          [!eForm? &eFormOnBeforeMailSent=`eForm2session` &formid=`memberdirectoryFormTpl` &noemail=`1` &tpl=`memberdirectoryFormTpl` &gotoid=`50` &protectSubmit=`0`!]


          This is all pretty straightforward if you’ve worked with the OnBeforeMailSent parameter before. Something to note: "noemail" obviously prevents eForm from sending an email, and "gotoid=`50` points to the second page you created in step 1 that contains the form (in my case, it has an ID of 50).

          3. Time to create the form Tpl. Mine looks like this:

          [+validationmessage+]
          <form method="post" action="[~[*id*]~]">
          <fieldset>
          <input type="hidden" name="formid" value="memberdirectoryFormTpl" />
          
          <div class="sendemail_container">
          <p>To take full advantage of the KanSPRA Member Directory, follow these instructions:</p>
          <ol>
          <li>To filter the list, type a keyword in the "Filter" input box (i.e., "northeast, "Blue Valley," "communications director").</li>
          <li>To sort the list, click a column heading (i.e., "Name," "Region"). Shift-click a second heading to sort a second category.</li>
          <li>To copy your sorted, filtered list to your clipboard, or to export it as a CSV or Excel file, click the appropriate icon on the right.</li>
          <li>To send an e-mail, place a checkmark next to individuals' names you want to message and click "Send E-mail."</li>
          </ol>
          <input type="submit" name="submit" value="Send E-mail (note: you must select e-mail recipients below first)">
          </div>
          
          <table id="tablesorter" class="tablesorter" border="0" cellspacing="1">
          <thead>
                      
          <tr>
          <th><input type="checkbox" name="checkall" id="checkall" value="checkall"></th>
          <th>Name</th>
          <th nowrap>District/Organization</th>
          <th nowrap>Phone</th>
          <th>E-mail</th>
          <th>Region</th>
                          
          </tr>
          </thead>
              
          <tbody>
          
          [[WebLoginPE? &type=`users` &usersList=`All Users:kanspra_usersNewOuterTpl:kanspra_usersNewTpl:fullname:ASC:`]] 
          
          </tbody>
          </table>
          
          <input type="hidden" id="emailvalue" name="emailvalue" eform="Hidden Field:string:1::" />
          
          </fieldset>
          
          </form>


          There are some important IDs in that form that make the checkboxes work with the JQuery plugins (for example, the last input in the form is a hidden field that is populated by JQuery with whatever names are checked).

          4. You probably noticed the WebLoginPE call. This is what actually generates the list of active users and lays them out in the nice table (the table styling, sorting, filtering and Excel output are all handled by awesome JQuery plugins called DataTables and TableTools -- check out my header files to see how I got those working properly). The "userslist" parameter was a new one for me and took some time to figure out. I can try to explain it further if it doesn’t make sense; just let me know.

          5. After the user selects the names he wants, eForm should add those e-mail address to session variables and send the user to the other page that you made in step 1. On this page, place this chunk of code:

          [[SESSION2Placeholders?]]
          <div class="emailsendlist"><strong>This message will be sent to:</strong> [+emailvalue+]</div>
          [!eForm? &formid=`memberdirectory_sendform` &to=`[+emailvalue+]` &tpl=`memberdirectory_sendform` &report=`memberdirectory_sendreport` &gotoid=`51` &vericode=`1` &subject=`Message from the KanSPRA Web Site`!]</p>


          Note that you can now use the "emailvalue" placeholder that was set on the previous page. The "gotoid" in this case is just a thank-you page, nothing special. There’s also nothing strange about the form Tpl, but if you want to see it, here it is:

          [+validationmessage+]
          <form id="kanspracontactform" method="post" action="[~[*id*]~]" enctype="multipart/form-data">
              <input type="hidden" name="formid" value="memberdirectory_sendform" />
          
              <p><label accesskey="n" for="name">Your Full Name:</label>
              <input type="text" name="name" maxlength="60" eform="Your Name::1:Expected at least two words:#REGEX /^\w+\s\w+/i" /></p>
          
              <p><label accesskey="e" for="email">Your E-mail Address:</label>
              <input type="text" name="email" size="40" maxlength="40" eform="Your Email Address:email:1" /></p>
              
              <p><label accesskey="c" for="comments">Your Message:</label>
              <textarea cols="40" rows="10" name="comments" eform="Comments:html:1"></textarea></p>
          
              <p><label accesskey="a" for="attachment">Attach File:</label>
              <input type="file" name="attachment" accept="text/plain,application/msword,application/rtf,application/pdf,text/html,text/html,image/jpeg,audio/mpeg,video/quicktime" eform="Attachment:file:0" />
          
              <p>
              <img src="[+verimageurl+]" alt="verification code" border="1"/>
              </p>
              <p>
              <label accesskey="c" for="vericode">Verification Code:</label>
              <input type="text" name="vericode" size="20" />
              </p>
              
              <p><input type="submit" name="submit" value="Send Message"></p>
          </form> 


          So...that’s everything! It’s a little complicated, but this does work. Let me know if you need me to clarify this! If anyone with more experience has a better way of doing this, I’d love to hear it!
            • 27672
            • 168 Posts
            wow - thank you for the detail of your explanation! just reading through it once it seems to make sense, i will try to implement this very soon. again thank you so much.
              • 27672
              • 168 Posts
              aladage, what do your kanspra_usersNewOuterTpl and kanspra_usersNewTpl chunks look like?
                • 27672
                • 168 Posts
                after looking at your source code, on kanspra, it’s probably something like this for the chunks:

                kanspra_usersNewOuterTpl:
                [+view.list+]


                kanspra_usersNewTpl:
                <tr>
                <td><input name="email_check" value="[+view.email+]" type="checkbox" /></td>
                <td><strong>[+view.fullname+]</strong></td>
                <td>etc...</td>
                </tr>


                is that correct? will probably give this a shot when i get back to work.
                  • 813 ☆ A M B ☆
                  • 326 Posts
                  Sorry for the slow response! Yes, you’re very close on those two Tpls. kanspra_usersNewOuterTpl is [+view.list+]. kanspra_usersNewTpl is a bit more complicated because I use some PHx to show/not show certain info depending on whether they filled it out in their profile. I also use it to populate their "region" within the organization based on the county they choose in their profile. You probably don’t need most of it, but it looks like this:

                  <tr>
                  <td>
                  <input type="checkbox" name="email_check" value="[+view.username+]">
                  </td>
                  <td>
                  <strong>[+view.fullname+]</strong><br />
                  [+phx:input=`[+view.title+]`:is=``:then:``:else=`[+view.title+]<br />`+]
                  </td>
                  <td nowrap>
                  [+phx:input=`[+view.district+]`:is=``:then:``:else=`[+view.district+]<br />`+]
                  [+phx:input=`[+view.address+]`:is=``:then:``:else=`[+view.address+]<br />`+]
                  [+phx:input=`[+view.city+]`:is=``:then:``:else=`[+view.city+], `+]
                  [+phx:input=`[+view.state+]`:is=``:then:``:else=`[+view.state+] `+]
                  [+phx:input=`[+view.zip+]`:is=``:then:``:else=`[+view.zip+]`+]
                  </td>
                  <td nowrap>
                  [+phx:input=`[+view.phone+]`:is=``:then:``:else=`[+view.phone+] (Work)<br />`+]
                  [+phx:input=`[+view.mobilephone+]`:is=``:then:``:else=`[+view.mobilephone+] (Home)<br />`+]
                  [+phx:input=`[+view.fax+]`:is=``:then:``:else=`[+view.fax+] (Fax)`+]
                  <td id="emailcolumn">
                  [+phx:input=`[+view.username+]`:is=``:then:``:else=`<a href="mailto:[+view.username+]">[+view.username+]</a>`+]
                  </td>
                  <td>
                  [+phx:input=`[+view.county+]`:is=`Anderson`:or:is=`Atchison`:or:is=`Doniphan`:or:is=`Douglas`:or:is=`Franklin`:or:is=`Jefferson`:or:is=`Johnson`:or:is=`Leavenworth`:or:is=`Linn`:or:is=`Miami`:or:is=`Wyandotte`:then=`Northeast`:else=``+]
                  
                  [+phx:input=`[+view.county+]`:is=`Allen`:or:is=`Barber`:or:is=`Bourbon`:or:is=`Butler`:or:is=`Chase`:or:is=`Chatauqua`:or:is=`Cherokee`:or:is=`Cowley`:or:is=`Crawford`:or:is=`Elk`:or:is=`Greenwood`:or:is=`Harper`:or:is=`Harvey`:or:is=`Kingman`:or:is=`Labette`:or:is=`Marion`:or:is=`McPherson`:or:is=`Montgomery`:or:is=`Neosho`:or:is=`Pratt`:or:is=`Reno`:or:is=`Rice`:or:is=`Saline`:or:is=`Sedgwick`:or:is=`Stafford`:or:is=`Sumner`:or:is=`Wilson`:or:is=`Woodson`:then=`South Central`:else=``+]
                  
                  [+phx:input=`[+view.county+]`:is=`Barton`:or:is=`Cheyenne`:or:is=`Clark`:or:is=`Cloud`:or:is=`Comanche`:or:is=`Decatur`:or:is=`Edwards`:or:is=`Ellis`:or:is=`Ellsworth`:or:is=`Finney`:or:is=`Ford`:or:is=`Gove`:or:is=`Grant`:or:is=`Gray`:or:is=`Greeley`:or:is=`Hamilton`:or:is=`Haskell`:or:is=`Hodgeman`:or:is=`Jewell`:or:is=`Kearny`:or:is=`Kiowa`:or:is=`Lane`:or:is=`Lincoln`:or:is=`Logan`:or:is=`Meade`:or:is=`Mitchell`:or:is=`Morton`:or:is=`Ness`:or:is=`Norton`:or:is=`Osborne`:or:is=`Ottawa`:or:is=`Pawnee`:or:is=`Rawlins`:or:is=`Republic`:or:is=`Rooks`:or:is=`Rush`:or:is=`Russell`:or:is=`Scott`:or:is=`Seward`:or:is=`Sheridan`:or:is=`Sherman`:or:is=`Smith`:or:is=`Stanton`:or:is=`Stevens`:or:is=`Thomas`:or:is=`Trego`:or:is=`Wallace`:or:is=`Wichita`:then=`West`:else=``+]
                  
                  [+phx:input=`[+view.county+]`:is=`Brown`:or:is=`Clay`:or:is=`Coffey`:or:is=`Dickinson`:or:is=`Geary`:or:is=`Jackson`:or:is=`Lyon`:or:is=`Marshall`:or:is=`Morris`:or:is=`Nemaha`:or:is=`Osage`:or:is=`Pottawatomie`:or:is=`Riley`:or:is=`Shawnee`:or:is=`Wabaunsee`:or:is=`Washington`:then=`North Central`:else=``+]
                  
                  [+phx:input=`[+view.county+]`:is=`Other`:then=`Other`:else=``+]
                  
                  </td>
                  </tr>


                  Hope this helps! If you get it working and don’t mind sending a link, I’d love to see how someone else used this.
                    • 27672
                    • 168 Posts
                    aladage, sure - i’d love to show you the final product. i might make a couple changes to make it function more how i need it to for this application (buttons/links/radios instead of checkboxes, since i cannot allow sending to multiple people at once).

                    do you mind if i email you the results or any other questions i have? so we don’t keep bumping this message to the top of the forums to have a 2-person conversation? i’ll post the final, final product here to share of course. my application is also for educational sites (like kanspra).
                      • 813 ☆ A M B ☆
                      • 326 Posts
                      That would be fine! Just PM me.