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.

WP 3.3 GF 1.6 CheckBox $entry not returning values

  1. I have a GF with some check boxes, I have enabled values and populate dynamically , but when I do a var_dump of the $entry in the gform_post_submission I always get an empty sting for both of the checkbox values e.i [7.1] & [7.2] both have an empty string (7 is my check box field) no matter if they are checked or not. I'm not sure where i'm going wrong here because I have done this before no problem. I also don't know if this is related to the WP 3.3 upgrade I did or just a coincidence? Forms I created before the upgrade work and I can var_dump the $entry and see my value string as expected.

    Has anyone else had the same problem? I did originally created the form by duplicating a previous one, but when I found the issue I deleted the checkbox field and created a new one just to be on the safe side.

    Thanks for any help.

    Ben

    Posted 12 years ago on Wednesday December 14, 2011 | Permalink
  2. I believe I have found the issue. On my form I had a dropdown select box that was used as a conditional items to allow a checkbox field to be shown or not. I was using this form while editing an item so I didn't want the dropdown select box to be used as the item had already been set. The conditional statement was operating as expected with the checkboxes being shown or not shown. But I had used jQuery to disable the dropdown input.

    jQuery('#input_21_1').attr('disabled', 'disabled');

    So the dropdown select box has disabled so it couldn't be changed, however by doing this the checkbox $entry details were always blank. Could you let me know if this is a Bug or not?

    I have got over this by using jQuery is hide the dropdown select box and the form now works as I expect it to.

    jQuery('#field_21_1').css('display', 'none');

    Ideally I would have liked the dropdown select box to display.

    Regards

    Ben

    Posted 12 years ago on Thursday December 15, 2011 | Permalink
  3. Hi bazchas,

    I wasn't able to recreate this locally. Anyway we could test it on your setup?

    Posted 12 years ago on Thursday December 15, 2011 | Permalink
  4. Hi I can't send you our setup as we are still in development, but I just did a quick form/page test to recreate it and found an interesting result when I was using jQuery to disabled a drop down list box that was being used as a conditional statement for some check boxes.

    I created a form with two fields on it, field 1 was a "drop down" with two choices set up in the editor, I enabled the values and set the values of each to 1 & 2. This is the only options I setup in the form editor for the "drop down" field. I then created a second field of type checkboxes. I enabled the values and set the values to 1,2,3 for the three default check boxes for the field. In the advanced options for this field I "Enabled Conditional Logic" So this field would "show this field is All of the following match" : "Selection(name of my drop down) is First Choice".

    So a pretty simple form. Below is the PHP for this form.

    [php]
    <?php
    
    /**
     * @author Ben Hooper
     * @copyright 2011
     */
    
    add_filter('gform_pre_render_22', 'populateCheckBoxTest');
    add_action("gform_post_submission_22", "submitCheckBoxTest", 10, 2);
    
    /**
     *Populate the form
     * @param form $form The form to populate the details with
     * @return the form being modified.
     */
    function populateCheckBoxTest($form)
    {
        //run the javascript to initialise this form
        echo "<script language=javascript>";
        echo "jQuery(document).ready(function () {";
            echo "jQuery('#input_22_1').val('1');";
            //echo "jQuery('#field_22_1').css('display', 'none');";   //Hides the field and the entry works
            echo "jQuery('#input_22_1').attr('disabled', 'disabled');"; //disables the input and the entry doesn't work
        echo "});";
        echo "</script>";
        return $form;
    }
    
    /**
     * Submit the form
     * @param array $entry An array of objects including in the form
     * @param form $form The form forming no
     */
    function submitCheckBoxTest($entry, $form)
    {
        var_dump($entry);
    }
    
    ?>

    So again really basic, I've put the Javascript inline in the gform_pre_render function, I was previously calling a javascript function, but this keeps is simple. When I disable the field using ('#input_22_1').attr('disabled', 'disabled'); and submit the form the var_dump of the $entry is:

    bool(false)

    however when I hide the dropdown field using ('#field_22_1').css('display', 'none'); the var_dump of the $entry returns the data correctly:
    e.g.

    ...NULL ["user_agent"]=> string(106) "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2" ["status"]=> string(6) "active" [1]=> string(1) "1" ["2.1"]=> string(1) "1" ["2.3"]=> string(1) "3" ["2.2"]=> string(0) "" }

    Hope that helps, but please feel free to ask anything else.

    Regards

    Ben

    Posted 12 years ago on Friday December 16, 2011 | Permalink
  5. Hi, bazchas,

    The problem of the data not being available is most likely because when you use the disable attribute of a field, the field data is not available in a form submission, which is also why using display:none works (the field isn't disabled, just hidden). You could instead try setting it to readOnly using javascript . The drop down will still not be able to be changed and visible, but should submit the data. Take a look at this article which explains how the disable and readOnly attributes work - http://www.w3.org/TR/html4/interact/forms.html#h-17.12

    Posted 12 years ago on Friday December 16, 2011 | Permalink
  6. Hi thanks for your reply, yup making the input read only will do what I want and keep the display there. Moving on to new forms I will give that a try and see how I get on. Thanks for your quick response, very impressed.

    Regards

    Ben

    Posted 12 years ago on Saturday December 17, 2011 | Permalink

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