• I want to include the validate on blank for free_text field.
    My code as follow;

    
    [checkbox* your-selection id:your-selection exclusive free_text "Twitter" "Facebook" "Other"]
    

    My purpose is when use check on last checkbox (Other), then an input box is show (free_text),
    But I also want to validate the blank of this input field.

    Could you teach me how to do ?

    Thanks

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

    (@takayukister)

    You need to add a custom validation filter. If you are familiar with PHP coding, try https://contactform7.com/2015/03/28/custom-validation/

    Thread Starter hung99hn

    (@hung99hn)

    Thanks for your reply,
    I have tried as follow but error message is not shown. Could you help me to find what i am doing wrong?

    [checkbox* fav id:fav exclusive free_text "本サイト" "Twitter" "Facebook" "コンテスト募集サイト" "知人から紹介" "その他"][text fav-etc placeholder "雑誌など"]
    <span class="wpcf7-custom-item-error fav fav-etc"></span>
    

    in function.php

    function wpcf7_validate_fav_etc( $result , $tag ) {
    	$tag = new WPCF7_Shortcode( $tag );
    	if ( 'fav ' == $tag->name ) {
    		if (
        // 「好きなもの」(fav)が入力されていて、チェックボックスの選択に「その他」が含まれる
        ( isset( $_POST['fav'] ) && in_array( 'その他', $_POST['fav'] ) )
        // 「好きなもの」の「その他」の欄が未入力
        && ( ! isset( $_POST['fav-etc'] ) || 0 == mb_strlen( trim( $_POST['fav-etc'] ) ) )
      ) {
        $result['valid'] = false;
        $result['reason'] = array( 'fav-etc' => ' 項目必須です。');
    	
        return $result;
      }
    	}
      
     
      return $result;
    }
    add_filter( 'wpcf7_validate_text', 'wpcf7_validate_fav_etc' , 20,2);
    

    Reference: https://wpcj.net/1130

    • This reply was modified 8 years, 4 months ago by hung99hn.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Validate of input free_text of checkbox’ is closed to new replies.