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.

isSelected checkbox usage

  1. I am having trouble figuring out the proper use of isSelected when it comes to checkboxes. Basically I want to find out if a checkbox has been selected. With the function below I am able to get the text, but I just can't seem to figure out how to detect if it is checked.

    add_action("gform_pre_submission_1", "pre_submission_handler");
    
    function pre_submission_handler($form){
    	$industry = "";
    	foreach($form['fields'] as &$field){
    		if ($field['type'] == 'checkbox') {
    			foreach($field['choices'] as $choice) {
    				$industry  .= $choice["text"] . ",";
    				$industry  .= $choice["isSelected"] . ",";
    			}
    		}
    	}
    
       	$_POST["input_18"] = $industry;
    }
    Posted 8 years ago on Friday July 8, 2011 | Permalink
  2. I have forwarded this to one of our developers who is going to take a look and provide some feedback. He is currently traveling so it may take some time for him to respond. Bear in mind this is considered a customization so turnaround may not be as quick as for a standard support request. But he should get to it relatively quickly.

    Posted 8 years ago on Friday July 8, 2011 | Permalink
  3. I figured it out.... someone owes me a hug. This is very similar to the add_checkbox_custom_fields, however this works on users as well.

    add_action("gform_pre_submission_1", "pre_submission_handler");
    
    function pre_submission_handler($form){
    	$values = "";
    
    	 foreach($form['fields'] as &$field){
    
            if($field['type'] != 'checkbox' || strpos($field['cssClass'], 'custom_field_') === false)
                continue;
    
            $field_id = $field['id'];
            $custom_field_name = str_replace('custom_field_', '', $field['cssClass']);
    
    		foreach($_POST as $key => $value){
    
                if(strpos($key, "_{$field_id}_") === false)
                    continue;
    
    		   $values .= $value . ",";
    
            }
    
    	 }
    	$_POST["input_18"] = $values;
    	return $form;
    }
    Posted 8 years ago on Friday July 8, 2011 | Permalink
  4. OK, I have cleaned up the code a little more. Just add the CSS class name custom_field_input_20 to your checkbox where input_20 is the name of a hidden field you want to get populated (not the Field Label but actually the name of the field if you view the source code of your form)

    add_action("gform_pre_submission_1", "pre_submission_handler");
    
    function pre_submission_handler($form){
    
           foreach($form['fields'] as &$field){
    
           if($field['type'] != 'checkbox' || strpos($field['cssClass'], 'custom_field_') === false)
                continue;
    
           $field_id = $field['id'];
           $custom_field_name = str_replace('custom_field_', '', $field['cssClass']);
    
    		foreach($_POST as $key => $value){
    
            if(strpos($key, "_{$field_id}_") === false)
    			continue;
    
    		 $_POST[$custom_field_name] .= $value . ",";
    		}
    	}
    
    	return $form;
    }
    Posted 8 years ago on Friday July 8, 2011 | Permalink