is_posted();
foreach ( $values as $key => $value ) {
$checked = false;
if ( in_array( $key + 1, (array) $defaults ) )
$checked = true;
if ( $posted) {
if ( $multiple && in_array( esc_sql( $value ), (array) $_POST[$name] ) )
$checked = true;
if ( ! $multiple && $_POST[$name] == esc_sql( $value ) )
$checked = true;
}
$checked = $checked ? ' checked="checked"' : '';
if ( is_array( $tag['labels'] ) && isset( $tag['labels'][$key] ) )
$label = $tag['labels'][$key];
else
$label = $value;
if ( $label_first ) { // put label first, input last
$item = '' . esc_html( $label ) . ' ';
$item .= '';
} else {
$item = '';
$item .= ' ' . esc_html( $label ) . '';
}
if ( $use_label_element )
$item = '';
$item = '' . $item . '';
$html .= $item;
}
$html = '' . $html . '';
$validation_error = '';
if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) )
$validation_error = $wpcf7_contact_form->validation_error( $name );
$html = '' . $html . $validation_error . '';
return $html;
}
wpcf7_add_shortcode( 'checkbox', 'wpcf7_checkbox_shortcode_handler', true );
wpcf7_add_shortcode( 'checkbox*', 'wpcf7_checkbox_shortcode_handler', true );
wpcf7_add_shortcode( 'radio', 'wpcf7_checkbox_shortcode_handler', true );
/* Validation filter */
function wpcf7_checkbox_validation_filter( $result, $tag ) {
global $wpcf7_contact_form;
$type = $tag['type'];
$name = $tag['name'];
$values = $tag['values'];
if ( is_array( $_POST[$name] ) ) {
foreach ( $_POST[$name] as $key => $value ) {
$value = stripslashes( $value );
if ( ! in_array( $value, (array) $values ) ) // Not in given choices.
unset( $_POST[$name][$key] );
}
} else {
$value = stripslashes( $_POST[$name] );
if ( ! in_array( $value, (array) $values ) ) // Not in given choices.
$_POST[$name] = '';
}
if ( 'checkbox*' == $type ) {
if ( empty( $_POST[$name] ) ) {
$result['valid'] = false;
$result['reason'][$name] = $wpcf7_contact_form->message( 'invalid_required' );
}
}
return $result;
}
add_filter( 'wpcf7_validate_checkbox', 'wpcf7_checkbox_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_checkbox*', 'wpcf7_checkbox_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_radio', 'wpcf7_checkbox_validation_filter', 10, 2 );
?>