Is there a way to save selected checkbox values to an array in the database row such as:
a:2:{i:0;s:9:"Breakfast";i:1;s:19:"Handicap Access"}
instead of saving an individual row and meta_id for each value?
Is there a way to save selected checkbox values to an array in the database row such as:
a:2:{i:0;s:9:"Breakfast";i:1;s:19:"Handicap Access"}
instead of saving an individual row and meta_id for each value?
This is not built-in to Gravity Forms, it would require custom coding.
You could add a hidden field on the form and use code in the gform_after_submission (http://www.gravityhelp.com/documentation/page/Gform_after_submission) hook to update the hidden field with whatever you need.
That might work. What I am trying to do is use the gform_save_field_value function to grab the selected values of a checkbox before anything is written to the database. Then I can add them to an array and post the array as the field value instead of individual rows for the same field with its individual values. I am a bit of a beginner and not sure how to grab the fields multiple selected values and add them to an array.
Any more help would be appreciated!
anybody have any ideas to somehow go in and edit the php so that gravity forms saves checkbox values in an array instead of as separate rows in the database?
We can't give advice on modifying the plugin files. You would have to look through the code yourself and see what is possible.
You can use a GF hook and an ACF function to achieve this. Not glamorous, but works...
add_action("gform_post_submission_4", "acf_post_submission", 10, 2);
function acf_post_submission ($entry, $form)
{
$post_id = $entry["post_id"];
$values = get_post_custom_values("[GF custom field name]", $post_id);
update_field("[ACF field key]", $values, $post_id);
}
I did not know ACF had an "update_field" function like that. If you are using the ACF plugin, that's a good way to do it.