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.