PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Display form entries using Search term

  1. I have a couple questions:

    1. How do I access the GFFormsModel class from the front end to display form entries - when I try to access this in a shortcode function, it does not work (see code below)

    2. How do I properly use the $search parameter on a specific form field (see code below)

    When I run the function i have so far, the GFFormsModel::get_leads public function is not being calkled, and the $myLeads = 1 (no data array)

    Please advise, thanks!

    ---

    // shortcode to display current post's inquiries - used for front-end dashboard
    add_shortcode( 'inquiries', 'ik_show_inquiries');
    function ik_show_inquiries($atts) {
    
    	if($atts['ID']){
    		//now i want to get the form entries while searching for the Post ID
    		//shortcode $atts['ID'] - data was submitted in one of the form fields)
    		//$myLeads = RGFormsModel::get_leads(3, '', 'DESC', $atts['ID'], '0', $page_size='99999999');
    		$myLeads = GFFormsModel::get_leads(3, '', 'DESC', $atts['ID'], '0', $page_size='99999999');
    	} 
    
        //return print_r($myLeads);
    
        if(is_array($myLeads)){
    		foreach($myLeads as $lead) {
    			$html .= print_r($lead)."<br>";
    		}
    	}
    
    	return $html;
    
    }
    Posted 11 years ago on Monday April 1, 2013 | Permalink
  2. OK, I got the function working, but I cannot determine if there is a way to limit the search to a specific field. Is this possible?

    Here is the working code

    // shortcode to display current post's inquiries - used for front-end dashboard
    add_shortcode( 'inquiries', 'ik_show_inquiries');
    function ik_show_inquiries($atts) {
    		//print_r($atts);exit;
    
    		//set vars
    		$form_id = '3';
            $search = $atts['search'];
    
    		// function to pull entries from one form
            $inquiries = RGFormsModel::get_leads($form_id, '', 'DESC', $search, '0', $page_size='99999999');
    		if(is_array($inquiries)){
    
    		// show # of inquiries?
    		if($atts['showcount']){
    			$count = count($inquiries);
    			if(!count)$count='0';
    			$html = count($inquiries);
    		}
    
    		// show full details?
    		if($atts['hidelist'])
    			return $html;
    
    		$html .= "<ul class='inquiries'>\n";
            // loop through all the returned results
            $html .= '<li>searching for: '.$atts['search']."</li>\n";
    
    			foreach ($inquiries as $inquiry) {
    
                    $html .= "\t<li>";
    				$html .= $inquiry['date_created'];
    				//$html .= ',pre.'.print_r($inquiry,true).'</pre>';
    				$html .= "</li>\n";
    
    			}
    		}
            $html .= '</ul>';
    
            // return the html output from the shortcode
            return $html;
    }
    Posted 11 years ago on Monday April 1, 2013 | Permalink
  3. I don't think you can limit the search to specific fields when using RGFormsModel::get_leads. You can use an additional loop beginning on line 13 to see if your specific field (in the $inquiries array) contains your $search string. Then, proceed with your results. Your first step is to pull out all the leads which have that text somewhere in the entry. The new step will check to see if the specific field contains the search string.

    Posted 11 years ago on Tuesday April 2, 2013 | Permalink

This topic has been resolved and has been closed to new replies.