Advertisement
chrishajer

Pull information from form entries with a shortcode

Nov 2nd, 2011
8,809
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement