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.

POST $data array labels/names

  1. I'm working on an integration, using gform_after_submission and the $data array.

    I was wondering if there's an easy way to make the array names more meaningful / consistent across multiple forms?

    For e.g. two forms with a Field calls "My Field", in one might have the ID 1 and in the other might be ID 2. As it stands, I need to map each form manually because I have to manually say that "My Field" is $data[1] in Form A, and $data[2] in Form B.

    I'd like for both to just be accessible as $data["MyField"]

    The reason I ask, is, I want this integration to work standard across multiple forms. As it stands, I would need to map all of the field IDs to a name then run it through the processor. I'd like to have GF do that for me though, so I don't need to map each form manually (allowing me to create and launch forms with ease).

    I suspect the answer is no, not without some major modifications. But you never know!

    Even if it was some easy way to map the Field ID to whatever the Field Label is in the form design. Or even the Admin Label.

    Posted 12 years ago on Monday December 17, 2012 | Permalink
  2. David Peralty

    Unfortunately not, as each field needs a unique name, and so we force this by taking control over naming each item in each form so it is unique.

    Posted 12 years ago on Monday December 17, 2012 | Permalink
  3. I've managed a workaround... I used gform_field_standard_settings to create another "label" type field.

    Then in the gform_after_submission hook I loop through all the form fields, creating a new array around the custom label.

    // loop through the form fields
    	    foreach($form['fields'] as $field) {
    	        if ($field["api"]) {
    	        	if (is_array($field["inputs"])) {
    		        	foreach ($field["inputs"] as $input) {
    		        		$newid = explode(".",$input['id']);
    			        	$data[$field["api"].$newid[1]] = array($input["label"], $entry["".$input['id']]);
    		        	}
    	        	} else {
    			        $data[$field["api"]] = array($field["label"], $entry[$field['id']]);
    			    }
    
    			    echo "<strong>".$field["api"]. ":</strong> ".$field["label"]."<br />";
    	        }
    	    }
    Posted 12 years ago on Monday December 17, 2012 | Permalink
  4. Thanks for that code Chris.

    Posted 12 years ago on Tuesday December 18, 2012 | Permalink