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.

Getting Form Object outside of standard hooks

  1. This is a somewhat uncommon request, but I have a client that wants to provide a custom HTML formatted email once a month to users. The users should only receive product notices based on their choices in their sign up form that they initially signed up with.

    I am using a Cron Job to process the PHP code. It will loop through all the users and return the relevant lead ID from the database (already working). My question now is - I know the form ID, I know the lead ID - but how do I get the form OBJECT so I can start to manipulate it and pull data from it?

    Below is the code I have in the for each user loop - please help!

    global $wpdb;
    		//Figuring out if user has submitted form before
    		$sql = "SELECT filtered.sort, l.*, d.field_number, d.value
    		FROM wp_rg_lead l
    		INNER JOIN wp_rg_lead_detail d ON d.lead_id =
    			SELECT @rownum:=@rownum + 1 as sort, id
    				SELECT distinct
    				FROM wp_rg_lead l
    				INNER JOIN wp_rg_lead_detail d ON d.lead_id =
    				l.form_id=". $_GET["formid"] ."
    				 AND created_by=". $iUserID ."
    				 AND status='active'
    				ORDER BY date_created DESC
    				LIMIT 1
    			) page
    		) filtered ON =
    		ORDER BY filtered.sort";
    		//initializing rownum
    		$wpdb->query("select @rownum:=0");
    		//getting results
    		$results = $wpdb->get_results($sql);
    		$resultArray = array();
    		foreach( $results as $result ){
    			$leadID = $result->id;
    		echo $leadID;

    The code above does return the correct leadID, but for some reason in the for each results it does loop multiple times when it should only loop once for one result. I am not concerned with that near as much as getting the form object so I can get the relevant checkbox data though.

    Thanks for any help.

    Posted 8 years ago on Thursday December 20, 2012 | Permalink
  2. Since you are going direct to the database, you can use the form ID to query the wp_rg_form_meta table.

    SELECT display_meta FROM
    WHERE form_id = $_GET["formid"];

    That will return a serialized array of all the form metadata. You can then use the php unserialize function to convert the data:

    $form_meta = unserialize($data);
    // debug?
    // print_r($form_meta);
    // retrieve the form title from the
    // serialized form_meta array
    $form_title = $form_meta['title'];

    Does that get you the information you need?

    Posted 8 years ago on Saturday December 22, 2012 | Permalink