mardi 15 décembre 2015

Reading Array and Getting Variable Output

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 trying to at least be 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 can get an 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] => ) )

I think that I'm going to need to get the [text] for each of the sub arrays into a new array. What's the syntax like to do that?

With the new array, I will be able to do a foreach loop, wrapping each element in HTML, using CSS to style the output like a checkbox.




Aucun commentaire:

Enregistrer un commentaire