WPCF7_Validation::invalidate
Marks a form control as an invalid field.
Метод класса: WPCF7_Validation{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$WPCF7_Validation = new WPCF7_Validation(); $WPCF7_Validation->invalidate( $context, $error );
- $context(WPCF7_FormTag|массив|строка) (обязательный)
- Context representing the target field.
- $error(WP_Error|строка) (обязательный)
- The error of the field.
Код WPCF7_Validation::invalidate() WPCF7 Validation::invalidate CF7 6.1.5
public function invalidate( $context, $error ) {
if ( $context instanceof WPCF7_FormTag ) {
$tag = $context;
} elseif ( is_array( $context ) ) {
$tag = new WPCF7_FormTag( $context );
} elseif ( is_string( $context ) ) {
$tags = wpcf7_scan_form_tags( array( 'name' => trim( $context ) ) );
$tag = $tags ? new WPCF7_FormTag( $tags[0] ) : null;
}
$name = ! empty( $tag ) ? $tag->name : null;
if ( empty( $name ) or ! wpcf7_is_name( $name ) ) {
return;
}
if ( is_wp_error( $error ) ) {
$message = $error->get_error_message();
} else {
$message = $error;
}
if ( $this->is_valid( $name ) ) {
$id = (string) $tag->get_option( 'id', 'id', true );
if ( ! wpcf7_is_name( $id ) or str_starts_with( $id, 'wpcf7' ) ) {
$id = null;
}
$this->invalid_fields[$name] = array(
'reason' => (string) $message,
'idref' => $id,
);
}
}