is_posted(); foreach ( $values as $key => $value ) { $selected = false; if ( ! $empty_select && in_array( $key + 1, (array) $defaults ) ) $selected = true; if ( $posted ) { if ( $multiple && in_array( esc_sql( $value ), (array) $_POST[$name] ) ) $selected = true; if ( ! $multiple && $_POST[$name] == esc_sql( $value ) ) $selected = true; } $selected = $selected ? ' selected="selected"' : ''; if ( is_array( $tag['labels'] ) && isset( $tag['labels'][$key] ) ) $label = $tag['labels'][$key]; else $label = $value; $html .= ''; } if ( $multiple ) $atts .= ' multiple="multiple"'; $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( 'select', 'wpcf7_select_shortcode_handler', true ); wpcf7_add_shortcode( 'select*', 'wpcf7_select_shortcode_handler', true ); /* Validation filter */ function wpcf7_select_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 ( 'select*' == $type ) { if ( empty( $_POST[$name] ) || ! is_array( $_POST[$name] ) && '---' == $_POST[$name] || is_array( $_POST[$name] ) && 1 == count( $_POST[$name] ) && '---' == $_POST[$name][0] ) { $result['valid'] = false; $result['reason'][$name] = $wpcf7_contact_form->message( 'invalid_required' ); } } return $result; } add_filter( 'wpcf7_validate_select', 'wpcf7_select_validation_filter', 10, 2 ); add_filter( 'wpcf7_validate_select*', 'wpcf7_select_validation_filter', 10, 2 ); ?>