• Hello,
    I need help to validate a select I created through wpcf7_add_shortcode.

    When selected “notselect” I want to present an error message and do not send the form.

    I’ve tried everything! I thank anyone who can help me.

    The code of my select:

    wpcf7_add_shortcode('eventos_lista', 'createbox', true);
    function createbox(){
    			$lista_produtos = new WP_Query(array('showposts'=>100, 'post_type' => 'eventos'));
    			$output = "<select name='evento' id='evento' class='form-control' onchange='document.getElementById(\"evento\").value=this.value;'><option value='notselect'>Evento</option>";
    			//foreach ( $myposts as $post ) : setup_postdata($post);
    			while ($lista_produtos->have_posts()) : $lista_produtos->the_post();
    
    				$data = rwmb_meta( 'paulo_date' );
    				$ativo = rwmb_meta( 'paulo_radio' );
    				$title = get_the_title();
    				if($ativo == 1) {
    					$output .= "<option value='$title'>$title - $data</option>";
    				}
    
    			endwhile;
    			$output .= "</select>";
    			return $output;
    }

    thanks!

    https://www.ads-software.com/plugins/contact-form-7/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Thread Starter Paulo Estev?o

    (@pauloestevaons)

    Takayuki,
    I created the code below:

    add_filter( 'wpcf7_validate_eventos_lista*', 'custom_email_confirmation_validation_filter', 20, 2 );
    function custom_email_confirmation_validation_filter( $result, $tag ) {
        $tag = new WPCF7_Shortcode( $tag );
    
        if ( 'evento' == $tag->name ) {
            $evento = isset( $_POST['evento'] ) ? trim( $_POST['evento'] ) : '';
    
            if ( $evento == 'notselect') {
                $result->invalidate( $tag, 'Selecione um evento acima.' ) );
            }
        }
        return $result;
    }

    The filter is working, however it does not have the phrase “Please fill the required field.” under the select I created, similar to most inputs.

    If you want to see running: https://breventos.net/confirme-sua-presenca/

    thanks!

    Thread Starter Paulo Estev?o

    (@pauloestevaons)

    Please

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Validation select custom using wpcf7_add_shortcode’ is closed to new replies.