Please Note: We are no longer using forums to facilitate standard support. 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.

Getting selected values of checkboxes in gform_pre_submission

  1. sanz
    Member

    Hey all ... trying to get the checkbox selected values in the gform_pre_submission filter.

    My checkbox field ID is 8.

    I am looping through the $form['fields'] to isolate just the data in the checkboxes in field 8 like this:

    foreach($form['fields'] as &$field) {
    	    if($field['id'] === 8) {
    	    	$selectData['inputs'] = $field['inputs'];
    	    	$selectData['selections'] = $field['choices'];
    	    }
    	}

    $selectData gives me all data like:

    Array
    (
        [inputs] => Array
            (
                [0] => Array
                    (
                        [label] => Appliances
                        [id] => 8.1
                    )
    
                [1] => Array
                    (
                        [label] => Book Stores and Stationary
                        [id] => 8.2
                    )
    
                [2] => Array
                    (
                        [label] => Fashion and Accessories
                        [id] => 8.3
                    )
    
                [3] => Array
                    (
                        [label] => Food and Beverage
                        [id] => 8.4
                    )
    
                [4] => Array
                    (
                        [label] => Home and Living
                        [id] => 8.5
                    )
    
                [5] => Array
                    (
                        [label] => Technology
                        [id] => 8.6
                    )
    
            )
    
        [selections] => Array
            (
                [0] => Array
                    (
                        [text] => Appliances
                        [value] => 9
                        [isSelected] =>
                    )
    
                [1] => Array
                    (
                        [text] => Book Stores and Stationary
                        [value] => 10
                        [isSelected] =>
                    )
    
                [2] => Array
                    (
                        [text] => Fashion and Accessories
                        [value] => 8
                        [isSelected] =>
                    )
    
                [3] => Array
                    (
                        [text] => Food and Beverage
                        [value] => 6
                        [isSelected] =>
                    )
    
                [4] => Array
                    (
                        [text] => Home and Living
                        [value] => 7
                        [isSelected] =>
                    )
    
                [5] => Array
                    (
                        [text] => Technology
                        [value] => 15
                        [isSelected] =>
                    )
    
            )
    
    )

    However in the [selections] array I'm expecting the [isSelected] value to be set to something but it isn't. In the example above the form was submitted with Appliances, Food and Beverage and Home and Living preselected (checked) in the form and then Book Stores and Stationary checked manually.

    What am I missing? The gform_pre_submission filter should have access to all submitted form data shouldn't it?

    Thanks

    Posted 3 years ago on Friday March 23, 2012 | Permalink
  2. sciamannikoo
    Member

    Did you ever find a solution to your issue?
    I'm facing the same problem.

    Posted 2 years ago on Monday October 22, 2012 | Permalink
  3. sanz
    Member

    No not as yet ... I've put my project on hold at the moment. Will keep searching for a solution.

    Posted 2 years ago on Tuesday October 23, 2012 | Permalink
  4. sciamannikoo
    Member

    Thank you for your reply sanz.

    I wonder why nobody from GF answered yet...

    Posted 2 years ago on Tuesday October 23, 2012 | Permalink
  5. Same looking over here!

    Posted 1 year ago on Thursday May 30, 2013 | Permalink
  6. In the pre submission filter, the entry isn't created yet, so you can get a hold of the submitted values by inspecting the $_POST variables. Each checkbox item will have its own variable. For example, lets say I have a checkbox field whose Field Id is 1 and it has 3 choices, then I would access the value for each like the following:

    $value_of_first_checkbox = $_POST["input_2_1"];
    $value_of_second_checkbox = $_POST["input_2_2"];
    $value_of_third_checkbox = $_POST["input_2_3"];

    I hope this helps.

    Posted 1 year ago on Friday May 31, 2013 | Permalink

 

Support Tickets

Open A New Support Ticket
 Open A New Priority Support Ticket *

* Developer license holders only