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.

Bug - gform meta field - can't use boolean false

  1. tyndalewebteam
    Member

    We were tracking down a problem where a checkbox state was not being retained when trying to save as gform meta field.

    After investigating the code in forms_model.php and taking a look at the database, I noted that the records were always being inserted and never updated. So I cleared the lead_meta table and tried saving the ticked checkbox again. Saw the new record in the table. Then I tried to save it unticked and verified that it indeed updated the existing record. Next, I attempted to save the ticked checkbox and that's when a new record was inserted. From that point on, I found that whatever value, Boolean or otherwise, would just be inserted as a new record.

    Taking a look at the code for the gform_update_meta function, I found that the check for an existing record looked a little something like this:
    $meta_exists = gform_get_meta($entry_id, $meta_key) !== false; (line #2839)

    I also noted in the gform_get_meta function, we are converting null (actually nonexistent) records to false.
    $meta_value = $value == null ? false : maybe_unserialize($value); (line #2829)
    This leads me to believe that it was by design to return false in the case of a nonexistent meta field record.

    The problem with this is that when you save a Boolean false value--unwittingly or purposefully--it will forever be seen by the current logic as "nonexistent" and a new record will be created every save onward since the gform_get_meta function will always grab the first natural order record available and then blatantly lie about its whereabouts.

    Posted 12 years ago on Monday October 8, 2012 | Permalink
  2. I've asked the developers for their input on this one. Thank you for the detailed report of your findings.

    Posted 12 years ago on Monday October 8, 2012 | Permalink
  3. tyndalewebteam
    Member

    Thank you for passing that along. I look forward to hearing their response.

    Posted 12 years ago on Monday October 8, 2012 | Permalink
  4. Hi, tyndalewebteam,

    I would like to try and reproduce the issue. Can you provide me an export of your form and any GF filters you are using? I want to do exactly the same thing as you are doing. You can email the form export to dana@rocketgenius.com.

    Thanks.

    Posted 12 years ago on Tuesday October 9, 2012 | Permalink