mardi 15 décembre 2015

Using $_Post within a Function

By default, Gravity Form merge tags for checkboxes output the value of the selected option. If they choices for a question are English, Spanish, and Other, and the user selects English, the merge tag outputs:

english

My end goal is to be able to customize a Gravity Form merge tag output for checkboxes to include all of the options, checkbox-like format, and the selected option (checkbox is checked).

Right now, I'm able to return all of the options. Using this function,

add_action( 'gform_pre_submission_3', 'pre_submission_handler' ); function pre_submission_handler( $form ) {

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

    $the_fields = $selectData;

    foreach ($the_fields as $fields) {      

        print_r($fields);       
    }
    }
}

I get the output:

Array ( 
[0] => Array ( 
    [text] => English 
    [value] => Language: English 
    [isSelected] => 
    [price] => 
) 
[1] => Array ( 
    [text] => Spanish 
    [value] => Language: Spanish 
    [isSelected] => 
    [price] => 
) 
[2] => Array ( 
    [text] => Other (specify) 
    [value] => Other 
    [isSelected] => 
    [price] => 
) 
)

However,[isSelected] doesn't have a variable. Over on the GF forum, someone else had the same problem. GF said '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 have tried running the function with similar lines, but don't get any yield when I echo $value_of_first_checkbox on the confirmation page. How do I use $_POST to output a proper value?




Aucun commentaire:

Enregistrer un commentaire