| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'You are not allowed to call this page directly.' ); |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* Show the checkbox field on the front-end. |
| 8 |
* Extra line breaks show as space on the front-end when |
| 9 |
* the form is double filtered and not minimized. |
| 10 |
* |
| 11 |
* @phpcs:disable Generic.WhiteSpace.ScopeIndent |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( isset( $field['post_field'] ) && $field['post_field'] == 'post_category' ) { |
| 15 |
$type = $field['type']; |
| 16 |
do_action( 'frm_after_checkbox', compact( 'field', 'field_name', 'type' ) ); |
| 17 |
} elseif ( $field['options'] ) { |
| 18 |
$option_index = 0; |
| 19 |
foreach ( $field['options'] as $opt_key => $opt ) { |
| 20 |
if ( isset( $shortcode_atts ) && isset( $shortcode_atts['opt'] ) && ( $shortcode_atts['opt'] !== $opt_key ) ) { |
| 21 |
continue; |
| 22 |
} |
| 23 |
|
| 24 |
$field_val = FrmFieldsHelper::get_value_from_array( $opt, $opt_key, $field ); |
| 25 |
$opt = FrmFieldsHelper::get_label_from_array( $opt, $opt_key, $field ); |
| 26 |
|
| 27 |
/** |
| 28 |
* Allows changing the HTML of option label in choice field (radio, checkbox,...). |
| 29 |
* |
| 30 |
* @since 5.0.04 |
| 31 |
* |
| 32 |
* @param string $label Label HTML. |
| 33 |
* @param array $args The arguments. Contains `field`. |
| 34 |
*/ |
| 35 |
$label = apply_filters( 'frm_choice_field_option_label', $opt, compact( 'field' ) ); |
| 36 |
|
| 37 |
// init. |
| 38 |
$checked = ''; |
| 39 |
|
| 40 |
if ( ! FrmFieldsHelper::is_other_opt( $opt_key ) ) { |
| 41 |
// Let the checked state of 'Other' fields be determined solely by FrmFieldsHelper::prepare_other_input as below. |
| 42 |
// Without this check, one 'Other' field being checked leads to making all 'Other' fields checked on submit error |
| 43 |
// since they all have the same value attr of 'Other'. |
| 44 |
$checked = FrmAppHelper::check_selected( $field['value'], $field_val ) ? ' checked="checked"' : ''; |
| 45 |
} |
| 46 |
|
| 47 |
// Check if other opt, and get values for other field if needed |
| 48 |
$other_opt = false; |
| 49 |
$other_args = FrmFieldsHelper::prepare_other_input( compact( 'field', 'field_name', 'opt_key', 'field_val' ), $other_opt, $checked ); |
| 50 |
|
| 51 |
?> |
| 52 |
<div class="<?php echo esc_attr( apply_filters( 'frm_checkbox_class', 'frm_checkbox', $field, $field_val ) ); ?>" id="<?php echo esc_attr( FrmFieldsHelper::get_checkbox_id( $field, $opt_key ) ); ?>"><?php |
| 53 |
|
| 54 |
if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) { |
| 55 |
?><label for="<?php echo esc_attr( $html_id ); ?>-<?php echo esc_attr( $opt_key ); ?>"><?php |
| 56 |
} |
| 57 |
|
| 58 |
?><input type="checkbox" name="<?php echo esc_attr( $field_name ); ?>[<?php echo esc_attr( $other_opt ? $opt_key : '' ); ?>]" id="<?php echo esc_attr( $html_id ); ?>-<?php echo esc_attr( $opt_key ); ?>" value="<?php echo esc_attr( $field_val ); ?>"<?php |
| 59 |
echo $checked . ' '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 60 |
|
| 61 |
do_action( 'frm_field_input_html', $field ); |
| 62 |
|
| 63 |
if ( 0 === $option_index && FrmField::is_required( $field ) ) { |
| 64 |
echo ' aria-required="true" '; |
| 65 |
} |
| 66 |
|
| 67 |
?> /><?php |
| 68 |
|
| 69 |
if ( ! isset( $shortcode_atts ) || ! isset( $shortcode_atts['label'] ) || $shortcode_atts['label'] ) { |
| 70 |
echo ' ' . FrmAppHelper::kses( $label, 'all' ) . '</label>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 71 |
} |
| 72 |
|
| 73 |
$other_args = array( |
| 74 |
'other_opt' => $other_opt, |
| 75 |
'read_only' => $read_only, |
| 76 |
'checked' => $checked, |
| 77 |
'name' => $other_args['name'], |
| 78 |
'value' => $other_args['value'], |
| 79 |
'field' => $field, |
| 80 |
'html_id' => $html_id, |
| 81 |
'opt_key' => $opt_key, |
| 82 |
'opt_label' => $opt, |
| 83 |
); |
| 84 |
FrmFieldsHelper::include_other_input( $other_args ); |
| 85 |
|
| 86 |
unset( $other_opt, $other_args, $checked ); |
| 87 |
|
| 88 |
?></div> |
| 89 |
<?php |
| 90 |
++$option_index; |
| 91 |
}//end foreach |
| 92 |
}//end if |
| 93 |
|