This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Pull information from form entries with a shortcode

By: chrishajer on Nov 2nd, 2011  |  syntax: PHP  |  size: 1.10 KB  |  views: 3,015  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. // http://www.gravityhelp.com/forums/topic/query-submitted-forms-from-custom-page#post-39607
  3. // create shortcode to return names of participants for a specific form
  4. // usage: [participants form=37] where 37 is the form ID
  5. add_shortcode('participants', 'troop24_participants');
  6. function troop24_participants($atts) {
  7.         $form_id = $atts['form'];
  8.         // function to pull entries from one form
  9.         $scouts = RGFormsModel::get_leads($form_id, '1.6', 'ASC');
  10.         $html = "<ul class='participants'>\n";
  11.         // loop through all the returned results
  12.         foreach ($scouts as $participant) {
  13.                 // field 1.3 is the first name. I upper cased the first letter for consistency
  14.                 $fname    = ucfirst($participant['1.3']);
  15.                 // I wanted to show only the first initial of the last name, also upper case
  16.                 $linitial = strtoupper(substr($participant['1.6'],0,1));
  17.                 $html .= "\t<li>$fname $linitial</li>\n";
  18.         }
  19.         $html .= '</ul>';
  20.         // return the html output from the shorcode
  21.         return $html;
  22. }
clone this paste RAW Paste Data