WordPress.org

Ready to get started?Download WordPress

Forums

Gravity Forms - Update Post
Not working with List Field (8 posts)

  1. semyou
    Member
    Posted 1 year ago #

    Hi,

    I think that it is not working with the List Field. As in your function you are using $value = maybe_unserialize($value); and the value is not an array or a serialized string. It's indeed stored like 23|23|23|232.
    I will try to change the code to create an array out of this and see if the list field is displayed properly. If it does I will let you know, so you can update the core of your plugin.
    Thanks,

    http://wordpress.org/extend/plugins/gravity-forms-update-post/

  2. semyou
    Member
    Posted 1 year ago #

    OK. Just hacked the code of the plugin. This makes it work. You should remove the list from the switch case and make it separate into this.

    case 'list':
              $value = !is_array($value) ? array($value) : $value;
              $i=0;
              foreach ($field['choices'] as &$choice)
              {
              $field['defaultValue'][$choice['text']] = $value[$i];
                  $i++;
              }
              $field['defaultValue']=Array($field['defaultValue']);
           break;
  3. David_sa
    Member
    Posted 1 year ago #

    So happy that I found this! Cant really get it to work..

    Is this still working for you semyou?

    I had a look at the GF documentation for the Field Object Property "defaultValue".
    Doesn't look like it applies to list fields..
    http://www.gravityhelp.com/documentation/page/Field_Object

    The only other way I can think of is using the Field Value filter but that just feels like a bad workaround..
    Any suggestions?

    Thank in advance!

  4. David_sa
    Member
    Posted 1 year ago #

  5. semyou
    Member
    Posted 1 year ago #

    Hi David,

    Did you try my fix? Did you change the code of the plugin?

    Let me know.

  6. David_sa
    Member
    Posted 1 year ago #

    Yea, I tried it but could not get it to work.. I removed the list case from the switch and made it separate as per your instructions.

    The code runs without errors but nothing shows up in the list field.
    I think the array needs to be built in another way..
    It only adds the first row even if there's say 3 rows saved in the post.

    If I "print_r" the final array inserted in the $field['defaultValue'] it looks like this:

    Array ([0] => Array([Column-1] => text-col1|text-col2 [Column-2] => ))

    Only the first row is added to the array and the values for both my columns are added to the first column :/

    Do you know how Gravity Forms is expecting the default value for the list field? Cant find it anywhere.. If I knew how GF is expecting the array I could most likely change how the array is being put together.

  7. semyou
    Member
    Posted 1 year ago #

    Hi David,

    I have fixed the bug in the plugin to support lists. However, I included also removal of duplicates by deleting previous entries. Please check here. Let me know if you have questions.

    https://github.com/semyou/Gravity-Form-Post-Update-with-List-support

  8. David_sa
    Member
    Posted 1 year ago #

    Cool @semyou!

    I had to find a workaround for my project at the time. Will look at implementing this instead when I have time.
    Thanks for the follow-up!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags