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.

Prepopulate multiple columns list field with gform_pre_render

  1. Hi.
    I am trying to prepopulate a multiple columns list field with gform_pre_render. It's causing me some grief, cause I can add value to the $field['defaultvalue'], but only the first column is filled. The rest of the columns I cannot prepopulate.

    I am using this plugin: http://wordpress.org/extend/plugins/gravity-forms-update-post/, but the plugin does not fill out list field with multiple columns and I am just trying to fix the plugin, so I can use it and send the result to the author.

    Posted 12 years ago on Tuesday July 31, 2012 | Permalink
  2. Hi again.

    Is it not possible to prepopulate a list field with gform_pre_render filter hook?
    I simply want to fill the fields in this list field:
    http://www.box.com/shared/09b173125037b50e1fd2

    Or is it so simple, that I am just staring blind at it? :-)

    Posted 12 years ago on Tuesday July 31, 2012 | Permalink
  3. I'm not sure how to do it exactly, but can you try a couple things? How about dumping the $form or $entry after filling in a multiple-column list field like that, so you can get an idea of how to reference those particular fields/columns? Sometimes that's all it takes to figure out the proper syntax or 'trick' to it. If that does not help, I will try it myself or ping the developers to see if they have any insight.

    Also, take a look at this post from developer David Smith describing how the data is stored:
    http://www.gravityhelp.com/forums/topic/list-field-help

    Posted 12 years ago on Wednesday August 1, 2012 | Permalink
  4. Hi Chris.
    Thanks for getting back to me on this. :-)

    Yes, I have studied the $form/$entry dumb on this and I can't get it right.
    Here is part of the dump for this field:
    https://www.box.com/shared/b3ab15c81c754e62ddb8
    I have tried to add data to the "defaultvalue", but this doesn't help.

    Any clue?

    Posted 12 years ago on Wednesday August 1, 2012 | Permalink
  5. Help please help. :-)

    Posted 12 years ago on Wednesday August 1, 2012 | Permalink
  6. I can fill the first input field in the list field, when I convert the string to an array. Here you can see two ways I have manipulated the string and added it to the $field[defaultvalue].
    http://www.box.com/shared/572184b8ea9b7f80b897

    I just can't seem to fill out all three input fields.

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  7. skin29
    Member

    Hi Vayu
    what modifications did You make to get the first fields populated?

    I modified the plugin to but can't display any values in the fields.

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  8. Hi.

    It was difficult task, but I think I managed to solve it. It may not be pretty and most likely it can be done better but here it is. I had to modified file gravityforms-update--post.php, which I usually don't do. This was at about line 239.
    http://pastie.org/4379397

    Furthermore, I added this bit of code to about line 170.

    elseif ($field['type'] == 'post_custom_field' && isset($meta[$field['postCustomFieldName']]) && $field_type == 'list')
            {
              $field = $this->gform_populate_element($field, $field_type, $meta[$field['postCustomFieldName']]);
            }

    I haven't explained the code, as I don't really have the time, but I hope this makes sense. :-)

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  9. skin29
    Member

    Hi,
    I had similar code like You in line 170, after adding the "list" case in the switch statement - I still have no data in the form fields.

    Here is a array for the $result array

    http://pastie.org/4379717

    but still no data in the form fields

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  10. skin29
    Member

    Hi Vayu,
    I would be very grateful if You could post the result of the

    print_r( $field[ 'defaultValue' ] );

    for the list type field?

    Thanks!

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  11. This is for a list field with multiple columns:

    [defaultValue] => Array (
                [0] => Array(
                        [Column 1] => 111
                        [Column 2] => 222
                        [Column 3] => 333
                    )
                [1] => Array (
                        [Column 1] => 444
                        [Column 2] => 555
                        [Column 3] => 666
                    )
            )

    This is for a list field without multiple columns:

    [defaultValue] => Array(
                [0] => 777
                [1] => 888
                [2] => 999
           )

    http://www.box.com/shared/62fab23b6eead9fa0be4

    I have found an issue though. For some reason it is not possible to delete entire rows, by clicking on a minus button and then update.

    Posted 12 years ago on Thursday August 2, 2012 | Permalink
  12. skin29
    Member

    Thank You!,
    I get the exact same array structure for the $form['defaultValue'] but the list fields remained empty and the thing was I had left the checkbox "Allow field to be populated dynamically" checked.

    After I unchecked it I get the fields populated, but now I have the problem with duplicating fields when updating the post.

    Here is the code I used

    http://pastie.org/4382288

    Thanks again!

    Posted 12 years ago on Friday August 3, 2012 | Permalink
  13. skin29
    Member

    I eliminated the doubling by extending this piece of code in the gform_post_data() function

    http://pastie.org/4382382

    this way if it is a list type field it deletes all the custom meta associated with this field and adds new entries.

    Posted 12 years ago on Friday August 3, 2012 | Permalink

This topic has been resolved and has been closed to new replies.