Wednesday, January 18, 2023
HomeWordPress DevelopmentContact kind 7 customized enter tags don't validate

Contact kind 7 customized enter tags don’t validate


I’ve registered a custom_input tag and wish to make it required.
For the sake of testing, I even copied the very same code, which registers the default textual content tag.

The issue is that, once I attempt submitting the shape with the custom_input tag, it at all times passes and sends the shape. There isn’t a validation for required.

Right here is the code in my capabilities.php:

wpcf7_add_form_tag(['custom_input', 'custom_input*'],'wpcf7_custom_input_shortcode_handler', true);

operate wpcf7_custom_input_shortcode_handler($tag) {
    if (!is_a($tag, WPCF7_FormTag::class)) { return ''; }

    if ( empty( $tag->title ) ) {
        return '';
    }

    $validation_error = wpcf7_get_validation_error( $tag->title );

    $class = wpcf7_form_controls_class( $tag->kind, 'wpcf7-text' );

    if ( in_array( $tag->basetype, array( 'e mail', 'url', 'tel' ) ) ) {
        $class .= ' wpcf7-validates-as-' . $tag->basetype;
    }

    if ( $validation_error ) {
        $class .= ' wpcf7-not-valid';
    }

    $atts = array();

    $atts['size'] = $tag->get_size_option( '40' );
    $atts['maxlength'] = $tag->get_maxlength_option();
    $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 );
    $atts['readonly'] = $tag->has_option( 'readonly' );

    $atts['autocomplete'] = $tag->get_option(
        'autocomplete', '[-0-9a-zA-Z]+', true
    );

    if ( $tag->is_required() ) {
        $atts['aria-required'] = 'true';
    }

    if ( $validation_error ) {
        $atts['aria-invalid'] = 'true';
        $atts['aria-describedby'] = wpcf7_get_validation_error_reference(
            $tag->title
        );
    } else {
        $atts['aria-invalid'] = 'false';
    }

    $worth = (string) reset( $tag->values );

    if ( $tag->has_option( 'placeholder' )
        or $tag->has_option( 'watermark' ) ) {
        $atts['placeholder'] = $worth;
        $worth="";
    }

    $worth = $tag->get_default_option( $worth );

    $worth = wpcf7_get_hangover( $tag->title, $worth );

    $atts['value'] = $worth;
    $atts['type'] = $tag->basetype;
    $atts['name'] = $tag->title;

    $html = sprintf(
        '<span class="wpcf7-form-control-wrap" data-name="%1$s"><enter %2$s />%3$s</span>',
        esc_attr( $tag->title ),
        wpcf7_format_atts( $atts ),
        $validation_error
    );

    return $html;
}

That is an actual copy of the wpcf7_text_form_tag_handler operate however nonetheless it doesn’t work with validation.

After I change from custom_input* to textual content* it’s working.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments