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.

Possible to export all fields in Entry object?

  1. Hello,

    I have a form with many fields, over 100. I'm using gform_post_submission to send the data to a 3rd party server, but rather than having to go through and get every field's unique ID and input it as:

    'first_name' => $entry['1.3'],
     'last_name' => $entry['1.6'],

    etc.... Is there a simple way to have ALL fields posted without adding them one-by-one by field ID...? This can be quite tedious in forms with many fields...

    A prompt response is appreciated!

    Thank you

    Posted 13 years ago on Thursday February 16, 2012 | Permalink
  2. Hi, sales@luxsci.com,

    You can loop through the fields in the $form object and pull out the label/values for that field from the $entry object. Below is an example that loops through the $form object, checks to see if the field is a complex one like name or address, and gets the label and value. That information can be passed on to the third party however you want.

    function send_entry($entry, $form)
    {
           //only do this for a certain form (id 53 for example)
    	if ($form["id"] == 53)
    	{
    		foreach($form["fields"] as &$field)
    		{
    			//see if this is a multi-field, like name or address
    			if (is_array($field["inputs"]))
    			{
    				//loop through inputs
    				foreach($field["inputs"] as &$input)
    				{
    					$label = $input["label"];
    					//get value from entry object; change the id to a string
    					$value = $entry[strval($input["id"])];
    				}
    			}
    			else
    			{
    				$label = $field["label"];
    				//get value from entry object
    				$value = $entry[$field["id"]];
    			}
    		}
    	}
    }

    In the example above, when looping through the fields, you can also use the code below which will combine the data for the complex fields like name into one value

    //get the values for the field, will be an array if a complex field like name or address
    $raw_value = RGFormsModel::get_lead_field_value($entry, $field);
    //combines the data for complex fields, for example name will have the first and last combined into one value
    $value = GFCommon::get_lead_field_display($field, $raw_value, $entry["currency"], true, "text");

    Let me know if you have questions.

    Posted 13 years ago on Wednesday February 22, 2012 | Permalink

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