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.

Checkboxes to Arrays

  1. KindraPB
    Member

    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?

    Posted 12 years ago on Tuesday September 18, 2012 | Permalink
  2. 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.

    Posted 12 years ago on Wednesday September 19, 2012 | Permalink
  3. KindraPB
    Member

    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!

    Posted 12 years ago on Wednesday September 19, 2012 | Permalink
  4. KindraPB
    Member

    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?

    Posted 12 years ago on Friday September 21, 2012 | Permalink
  5. We can't give advice on modifying the plugin files. You would have to look through the code yourself and see what is possible.

    Posted 12 years ago on Saturday September 22, 2012 | Permalink
  6. 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);
    
    }
    Posted 12 years ago on Monday December 3, 2012 | Permalink
  7. 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.

    http://www.advancedcustomfields.com/

    Posted 12 years ago on Monday December 3, 2012 | Permalink