サポート » プラグイン » Contact Form 7: textareaタグのwrap="hard"が有効にならない

  • 解決済 katnuj9

    (@katnuj9)


    ContactForm7 1行に1000文字以上あると文字化け
    https://ja.forums.wordpress.org/topic/11182?replies=5

    にあるように、改行なしで長文が投稿されるケースが時々あり困っております。

    とりあえず回避するため、
    textareaタグに「wrap=”hard”」を追加して改行を入れるように試してみたのですが
    送信されてくるメールでは改行が入っておらず、
    約500文字(全角)で強制的に改行が入って文字化けしてしまいます。

    方法は、functions.phpに以下を追加し、
    HTMLソースには wrap=”hard”が追加されていることは確認できています。

    原因か代替案があればご教示いただけますと助かります。

    add_action( 'wpcf7_init', 'my_wpcf7_add_shortcode_textarea' );
    
    function my_wpcf7_add_shortcode_textarea() {
    	wpcf7_add_shortcode( array( 'textarea', 'textarea*' ),
    		'my_wpcf7_textarea_shortcode_handler', true );
    }
    
    function my_wpcf7_textarea_shortcode_handler( $tag ) {
    	$tag = new WPCF7_Shortcode( $tag );
    
    	if ( empty( $tag->name ) )
    		return '';
    
    	$validation_error = wpcf7_get_validation_error( $tag->name );
    
    	$class = wpcf7_form_controls_class( $tag->type );
    
    	if ( $validation_error )
    		$class .= ' wpcf7-not-valid';
    
    	$atts = array();
    
    	$atts['cols'] = $tag->get_cols_option( '40' );
    	$atts['rows'] = $tag->get_rows_option( '10' );
    	$atts['maxlength'] = $tag->get_maxlength_option();
    	$atts['class'] = $tag->get_class_option( $class );
    	$atts['id'] = $tag->get_option( 'id', 'id', true );
    	$atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
    
    	if ( $tag->has_option( 'readonly' ) )
    		$atts['readonly'] = 'readonly';
    
    	if ( $tag->is_required() )
    		$atts['aria-required'] = 'true';
    
    	$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
    
    	$value = (string) reset( $tag->values );
    
    	if ( '' !== $tag->content )
    		$value = $tag->content;
    
    	if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) {
    		$atts['placeholder'] = $value;
    		$value = '';
    	}
    
    	if ( wpcf7_is_posted() && isset( $_POST[$tag->name] ) )
    		$value = stripslashes_deep( $_POST[$tag->name] );
    
    	$atts['name'] = $tag->name;
    
    	$atts = wpcf7_format_atts( $atts );
    
    	$html = sprintf(
    		'<span class="wpcf7-form-control-wrap %1$s"><textarea wrap="hard" %2$s>%3$s</textarea>%4$s</span>',
    		$tag->name, $atts, esc_textarea( $value ), $validation_error );
    
    	return $html;
    }
1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック投稿者 katnuj9

    (@katnuj9)

    自己レスです。

    wrap=”hard”はブラウザ依存(?)のようなので諦め、
    適当な文字数で改行を入れる処理を追加する方法にしました。

    http://ameblo.jp/itboy/entry-10018306820.html

    を参考に、wpcf7_special_mail_tagsフィルターにフックさせました。

    フォーム [textarea message]
    メール [message2]
    のように設定し、以下をfunctions.phpに追加したところ
    何とか希望する動作になったようです。

    add_filter('wpcf7_special_mail_tags', 'my_special_mail_tags', 10 ,2);
    function my_special_mail_tags( $output, $name) {
    
    	$submission = WPCF7_Submission::get_instance();
    	$data = $submission->get_posted_data();
    
    	if('message2' == $name) {
    		$message = $data['message'];
    
    		(※上記URLと同じ処理)
    
    		return $output;
    	}
    }
1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック「Contact Form 7: textareaタグのwrap="hard"が有効にならない」には新たに返信することはできません。