Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-------------------------------------------------------
- //----------- Dynamically Populate Checkbox ------------
- //-------------------------------------------------------
- // Alex Cancado February 1, 2013
- // http://www.gravityhelp.com/forums/topic/not-all-the-selected-values-from-checkboxes-are-being-saved-to-the-database#post-137484
- // NOTE: update the '221' to the ID of your form
- add_filter('gform_pre_render_221', 'populate_checkbox');
- add_filter("gform_pre_submission_filter_221", "populate_checkbox");
- function populate_checkbox($form){
- foreach($form['fields'] as &$field){
- //NOTE: replace 3 with your checkbox field id
- $field_id = 3;
- if($field['id'] != $field_id)
- continue;
- // you can add additional parameters here to alter the posts that are retreieved
- // more info: http://codex.wordpress.org/Template_Tags/get_posts
- $posts = get_posts('numberposts=-1&post_status=publish');
- $input_id = 1;
- foreach($posts as $post){
- // skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
- if($input_id % 10)
- $input_id++;
- $choices[] = array('text' => $post->post_title, 'value' => $post->post_title);
- $inputs[] = array("label" => $post->post_title, "id" => "{$field_id}.{$input_id}");
- $input_id++;
- }
- $field['choices'] = $choices;
- $field['inputs'] = $inputs;
- }
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement