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.

Post Custom Field Default Value Altered in DB

  1. I am using a GF to create Woocommerce products from the frontend. I am storing some of the information to set the defaults for the product inside of the form with post custom field inputs and putting the info in the default value. This worked for all fields except one complex value, which keeps having erroneous meta inserted around it inside the db

    The value I am putting in is

    but it is appearing inside this: s:440:"here"; any ideas why this is happening?

    Posted 11 years ago on Wednesday September 26, 2012 | Permalink
  2. Anyone?

    Posted 10 years ago on Wednesday October 3, 2012 | Permalink
  3. We don't have any specific information about integration with Woocommerce. Are you adding the products through Woocommerce? Are you writing and storing that serialized value yourself? And is this erroneous information being stored in the Gravity Forms tables (rg_)?

    Can you show how you are doing things now? Maybe we can spot the problem.

    Posted 10 years ago on Wednesday October 3, 2012 | Permalink
  4. I don't believe it involves Woo too much, it seems to be something with how GF is storing the information. It is essentially a custom post type being created, and I am inserting the value with a custom field. Here are some screenshots to walk through

    Here is the meta I am trying to store in a custom field for the new post:
    This is the meta for the custom field used by the Woo gf add-on

    So I make this custom field box:
    And insert that meta from above as the default value: (of course I normally hide that)

    However, when I then use the form GF creates this as the meta value in the db:

    Posted 10 years ago on Wednesday October 3, 2012 | Permalink
  5. Looks like Gravity Forms is serializing the serialized data, which is why you see the s:440 there. It serialized the whole value. Gravity Forms is going to serialize any default value you enter. You are going to need a way to unserialize it before Woo gets hold of it. What functions does woo have available for modifying the value before using it? In Gravity Forms, we would use gform_pre_render to change the value before displaying it, when displaying the form anyway.

    You might be able to integrate gform_save_field_value to change the value before saving it, but I think that will create other problems. Maybe better if you can use gform_get_field_value and modifying the value before sending it to Woo?

    The issue is that Gravity Forms is serializing the default value, like it would serialize any value entered there. Gravity Forms does not know your value is already serialized.

    Posted 10 years ago on Wednesday October 3, 2012 | Permalink
  6. I think there may be a way to do that, but I need a little guidance with using the the two functions. There is a wp function called maybe_unserialize( ) that should hypothetically fix this, I just need to use the two gf functions properly. Here is what I tried:

    add_filter("gform_save_field_value_8", "save_field_value", 10, 4);
    function save_field_value($value, $lead, $field, $form){
               return   maybe_unserialize( $value );


    add_filter("gform_save_field_value_8", "save_field_value", 10, 4);
    function save_field_value($value, $lead, $field, $form){
        if($field["id"] == 8){
                maybe_unserialize( $value );
    return $value;

    It didn't work though, could it be serializing it after this hook?

    Posted 10 years ago on Thursday October 4, 2012 | Permalink
  7. I don't think I would unserialize it before storing it in Gravity Forms, since Gravity Forms expects it to be serialized. If you leave the storage alone, can you unserialize it before Woo gets hold of the value? They expect the data in a certain format, and you have that, but it's just encapsulated as one big string by Gravity Forms.

    Posted 10 years ago on Saturday October 6, 2012 | Permalink
  8. I was able to get a solution on wpquestions using gform_post_submission and then unserialize() to update the post meta. Thanks for your help pointing me in the right direction!

    Posted 10 years ago on Monday October 8, 2012 | Permalink
  9. That's a good way to do it. Thanks for the update.

    Here is a link to the topic for reference:

    Posted 10 years ago on Wednesday October 10, 2012 | Permalink

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