wpcf7_text_validation_filter() CF7 1.0
Хуков нет.
Возвращает
Null. Ничего.
Использование
wpcf7_text_validation_filter( $result, $tag );
Код wpcf7_text_validation_filter() wpcf7 text validation filter CF7 5.3.2
function wpcf7_text_validation_filter( $result, $tag ) {
$name = $tag->name;
$value = isset( $_POST[$name] )
? trim( wp_unslash( strtr( (string) $_POST[$name], "\n", " " ) ) )
: '';
if ( 'text' == $tag->basetype ) {
if ( $tag->is_required() and '' === $value ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
}
}
if ( 'email' == $tag->basetype ) {
if ( $tag->is_required() and '' === $value ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
} elseif ( '' !== $value and ! wpcf7_is_email( $value ) ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_email' ) );
}
}
if ( 'url' == $tag->basetype ) {
if ( $tag->is_required() and '' === $value ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
} elseif ( '' !== $value and ! wpcf7_is_url( $value ) ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_url' ) );
}
}
if ( 'tel' == $tag->basetype ) {
if ( $tag->is_required() and '' === $value ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
} elseif ( '' !== $value and ! wpcf7_is_tel( $value ) ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_tel' ) );
}
}
if ( '' !== $value ) {
$maxlength = $tag->get_maxlength_option();
$minlength = $tag->get_minlength_option();
if ( $maxlength and $minlength and $maxlength < $minlength ) {
$maxlength = $minlength = null;
}
$code_units = wpcf7_count_code_units( stripslashes( $value ) );
if ( false !== $code_units ) {
if ( $maxlength and $maxlength < $code_units ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_too_long' ) );
} elseif ( $minlength and $code_units < $minlength ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_too_short' ) );
}
}
}
return $result;
}