• Resolved jasoncfoster

    (@jasoncfoster)


    We have a field that is a drop down list which has many items in it that evaluate to a number. The first item has a value of 0 and that value is stored in the Gravity Forms entity as such. However, when our submission hook is processed the field does not get assigned to the $data array. It looks like the empty() function on line 99 ***!empty($value])*** is the culprit. That will evaluate to true if the value is 0 or “0”.

    I am going to modify for now but would love to have an update if one is in the works.

    https://www.ads-software.com/plugins/gravitate-gforms-api-helper/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Gravitate

    (@gravitate)

    Hi jasoncfoster,
    This should be resolved now.

    You will need to update the plugin.
    Then Try again.

    Please respond with whether it works or not
    Thanks

    Thread Starter jasoncfoster

    (@jasoncfoster)

    Works great! Thanks for the quick update!

    Plugin Author Gravitate

    (@gravitate)

    Awesome, Glad to hear it.

    Thread Starter jasoncfoster

    (@jasoncfoster)

    I might have spoken too soon. I think using isset() is always true now because of line 88 which causes all fields to be passed along even if empty. Instead of empty() or isset() I created an is_blank() test which takes numeric values of 0 into account. I’m not a seasoned PHP dev by any means so I didn’t know of a built-in function that would work. I found is_blank() on the codex for empty() in the user contributions.

    Line 99:
    if(!empty($field[‘ggah_’.str_replace(‘-‘, ‘_’, $api).’_field’]) && !empty($field[‘id’]) && !is_blank($value))

    Added function is_blank:
    function is_blank($value) {
    return empty($value) && !is_numeric($value);
    }

    This gets what you were originally after. Sorry I didn’t notice immediately but we had some tests going on that showed the issue.

    Plugin Author Gravitate

    (@gravitate)

    Actually,
    I decided to make it that if you created a field ID for the API Call then it would pass whatever the value is. Even Blank.

    If you don’t want pass that field for the call then don’t asign an API ID to that field.

    This is handled by:
    !empty($field[‘ggah_’.str_replace(‘-‘, ‘_’, $api).’_field’])

    If you specifically don’t want blank values passed then you would need to do that in your Hook Call.
    ie. loop through $data and unset any that are blank before you submit $data to your API.

    Thread Starter jasoncfoster

    (@jasoncfoster)

    We have a ton of conditional fields in our forms so we often have no value set for various entry fields. With the logic on line 88 which checks isset() and then either sets the $value to the value of the field or it sets $value to ” which will now be true in the isset($value) that you changed to from empty($value).

    In fact, due to some conditions we were successfully sending different fields to the same $data element due to the others being unset. I believe the changes I recommended still meet your overall design philosophy with just a tweak to support numeric 0 values to be passed through.

    My $0.02.

    Plugin Author Gravitate

    (@gravitate)

    But we also need to support blank values
    Example: ”

    Some may still want the field submitted to the API even if it is blank.
    So I need to make sure a solution also allows for that.

    Maybe the best solution would be to have a checkbox to “Hide Empty Values” per field.

    Do you think that would be best?

    Unfortunately I don’t have time to work on that right now.
    For now you would just have to loop through $data prior to submitting to your API and filter out the values you dont want.

    Sorry for the inconvenience

    Thread Starter jasoncfoster

    (@jasoncfoster)

    Totally makes sense and it might be best to add that additional property to the field. I was just saying that in order to keep the functionality as close to what you had before you would want to not use isset() to test $vvalue because the behavior is very different than what you had with empty().

    Thanks for spending time thinking through this. I don’t know how many other people are needing this type of thing but it’s a huge lifesaver for us. Mapping to an API is hard enough without adding the GF naming convention for fields into the mix. We’ll have several forms that will all end up mapping identically with your plugin.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Not passing the value "0"’ is closed to new replies.