Reputation: 1585
On my Gravity form I have a number of multiple select fields (sets of checkboxes) and my function is using the gform_after_submission
hook to get the data from the entry object to send off a request to an external API.
For the multiple select fields, how do I get a list of all selected options? I can see that there are entries like "4.1" => "Option A" but it strikes me as tedious to manually have to try every option to see if its listed or not. And I would assume that I'm just missing something in the documentation that would allow me to extract a list of all selected options either as an array or a comma-separated string or something like that.
Can anyone point me in the right direction?
Upvotes: 1
Views: 4277
Reputation: 776
You can retrieve a comma separated string containing the selected checkbox field choices by using the GF_Field::get_value_export() method which was added in Gravity Forms 1.9.13. Here's an example:
$field_id = 4;
$field = GFFormsModel::get_field( $form, $field_id );
$field_value = is_object( $field ) ? $field->get_value_export( $entry ) : '';
The above would return the values for the selected choices, if you wanted to return the choice text you would set the third parameter of get_value_export() to true e.g.
$field_value = is_object( $field ) ? $field->get_value_export( $entry, $field_id, true ) : '';
Upvotes: 4