name ) ) { return ''; } $validation_error = wpcf7_get_validation_error( $tag->name ); $class = wpcf7_form_controls_class( $tag->type, 'wpcf7-text' ); $class .= ' wpcf7-validates-as-rut'; if ( $validation_error ) { $class .= ' wpcf7-not-valid'; } if( $tag->has_option( 'onformat' )){ $class .= ' wpcf7-rut-onformat'; } if( $tag->has_option( 'onlynumbers' )){ $class .= ' wpcf7-rut-onlynumbers'; } $atts = array(); $atts['size'] = $tag->get_size_option( '40' ); $atts['maxlength'] = '9'; $atts['minlength'] = $tag->get_minlength_option(); if ( $atts['maxlength'] and $atts['minlength'] and $atts['maxlength'] < $atts['minlength'] ) { unset( $atts['maxlength'], $atts['minlength'] ); } $atts['class'] = $tag->get_class_option( $class ); $atts['id'] = $tag->get_id_option(); $atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true ); if ( $tag->is_required() ) { $atts['aria-required'] = 'true'; } $atts['aria-invalid'] = $validation_error ? 'true' : 'false'; $value = (string) reset( $tag->values ); if ( $tag->has_option( 'placeholder' ) or $tag->has_option( 'watermark' ) ) { $atts['placeholder'] = $value; $value = ''; } $value = $tag->get_default_option( $value ); $value = wpcf7_get_hangover( $tag->name, $value ); $atts['value'] = $value; if ( wpcf7_support_html5() ) { $atts['type'] = $tag->basetype; } else { $atts['type'] = 'text'; } $atts['name'] = $tag->name; $atts = wpcf7_format_atts( $atts ); $html = sprintf( '%3$s', sanitize_html_class( $tag->name ), $atts, $validation_error ); return $html; } static function tag_generator() { if (! function_exists( 'wpcf7_add_tag_generator')) return; wpcf7_add_tag_generator('rut', 'RUT', 'wpcf7-tg-pane-rut', array(__CLASS__, 'rut_pane') ); } static function rut_pane( $contact_form, $args = '' ) { ?>
Genera una etiqueta de formulario para un campo de entrada RUT. La validación del campo está contemplado por defecto.
Tipo de campo
Tipo de campo


array( 'description' => 'El RUT que introdujo el usuario no es válido', 'default' => 'El RUT que has introducido no es válido.', ), ) ); return $messages; } static function validation_filter($result, $tag) { $name = $tag->name; $value = isset( $_POST[$name] ) ? trim( wp_unslash( strtr( (string) $_POST[$name], "\n", " " ) ) ) : ''; if ( 'rut' == $tag->basetype) { if( $tag->is_required() and '' == $value ) { $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) ); }elseif ('' != $value and !self::validate_rut($value)) { $result->invalidate( $tag, wpcf7_get_message( 'invalid_rut' ) ); } } return $result; } static function validate_rut($rut){ if (!preg_match("/^[0-9.]+[-]?+[0-9kK]{1}/", $rut)) { return false; } $rut = preg_replace('/[\.\-]/i', '', $rut); $dv = substr($rut, -1); $number = substr($rut, 0, strlen($rut) - 1); $i = 2; $sum = 0; foreach (array_reverse(str_split($number)) as $v) { if ($i == 8) $i = 2; $sum += $v * $i; ++$i; } $dvr = 11 - ($sum % 11); if ($dvr == 11) $dvr = 0; if ($dvr == 10) $dvr = 'K'; if ($dvr == strtoupper($dv)) return true; else return false; } } new CF7RUT; /** * ------------------------------------------------------------------------ * Get plugin url * ------------------------------------------------------------------------ */ function wpcf7rf_plugin_url( $path = '' ) { $url = plugins_url( $path, WPCF7RF_PLUGIN ); if ( is_ssl() && 'http:' == substr( $url, 0, 5 ) ) { $url = 'https:' . substr( $url, 5 ); } return $url; } /** * ------------------------------------------------------------------------ * Add required script * ------------------------------------------------------------------------ */ add_action( 'wp_enqueue_scripts', 'wpcf7rf_enqueue_scripts', 20, 0 ); function wpcf7rf_enqueue_scripts() { wp_enqueue_script('wpcf7rf-scripts', wpcf7rf_plugin_url('scripts.js?'.time()), null, null, true); }