LLMS_Form_Field::explode_options_to_fields( string $is_hidden = false )

Returns an array of form field objects from this checkbox or radio field’s options array.


Parameters Parameters

$is_hidden

(string) (Optional) If true, returns only the checked fields and sets their type to 'hidden', else returns all options as $this->settings['type'] form fields.

Default value: false


Top ↑

Return Return

(LLMS_Form_Field[])


Top ↑

Source Source

File: includes/forms/class-llms-form-field.php

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
public function explode_options_to_fields( $is_hidden = false ) {
 
    $fields = array();
    $value  = ! empty( $this->settings['value'] ) || is_array( $this->settings['value'] )
        ? $this->settings['value']
        : $this->settings['default'];
 
    foreach ( $this->settings['options'] as $key => $val ) {
 
        $name    = $this->settings['name'];
        $checked = $value === $key;
 
        if ( 'checkbox' === $this->settings['type'] ) {
            $name    .= '[]';
            $value   = is_array( $value ) ? $value : array( $value );
            $checked = in_array( $key, $value, true );
        }
 
        if ( $is_hidden && ! $checked ) {
            continue;
        }
 
        $fields[] = new self(
            array(
                'data_store' => false,
                'id'         => sprintf( '%1$s--%2$s', $this->settings['id'], $key ),
                'name'       => $name,
                'value'      => $key,
                'label'      => $val,
                'checked'    => $checked,
                'type'       => $is_hidden ? 'hidden' : $this->settings['type'],
            )
        );
    }
 
    return $fields;
}


Top ↑

Changelog Changelog

Changelog
Version Description
6.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.