Created
November 3, 2015 21:11
-
-
Save RickeyMessick/fc1849be8305d253c921 to your computer and use it in GitHub Desktop.
Gravity Forms get all fields function to use with gform_after_submission to display just filled out fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_all_fields($entry, $form) | |
{ | |
//only do this for a certain form (id 53 for example) | |
// if ($form["id"] == 17) | |
//{ | |
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"])]; | |
if (!empty($value)) { | |
$output .= $label . ':' . $value . ' '; | |
} | |
//print_r($output); | |
} | |
} | |
else | |
{ | |
$label = $field["label"]; | |
//get value from entry object | |
$value = $entry[$field["id"]]; | |
if (!empty($value)) { | |
$output .= $label . ':' . $value . ' '; | |
} | |
//print_r($output); | |
} | |
} | |
//print_r($output); | |
return $output; | |
// } | |
} |
What about
// Get the Form fields
$form_id = 1;
$form = RGFormsModel::get_form_meta($form_id);
// Run through the fields to grab an object of the desired field
$field = RGFormsModel::get_field( $form, $field_id );
echo $field->label // Gets the label
echo $field->inputName // Gets the name
echo $field->type // Gets the type
echo $field->cssClass // Gets the CSS Classes as a string
Or:
$form_id = 1;
$form = RGFormsModel::get_form_meta($form_id);
$fields = array();
if(is_array($form["fields"])){
foreach($form["fields"] as $field){
if(isset($field["inputs"]) && is_array($field["inputs"])){
foreach($field["inputs"] as $input)
$fields[] = array($input["id"], GFCommon::get_label($field, $input["id"]));
}
else if(!rgar($field, 'displayOnly')){
$fields[] = array($field["id"], GFCommon::get_label($field));
}
}
}
echo "<pre>";
print_r($fields);
echo "</pre>";
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I want to display only the filled fields before the submission.
For that, I am using add_action( 'gform_pre_submission', 'pre_submission' ). But it doesn't seems to work. I haves used only the number fields.
Please help.
Thanks in advance!