• Resolved Zougou

    (@zougou)


    Hi,

    I’d like to know if this is possible to prevent users to insert line breaks in textarea field (advanced editor deactivated) ?

    Also, is it possible to prevent all html tags ?
    For example, if a <b> tag is inserted in textarea, I’d like to have textarea value without <b> tag in the email notification send to admin.

    Thanks in advance for your time,
    Best regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Zafer – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @zougou,

    Please try the following snippets for your issues as mu-plugins

    1- to disable textarea line breaks

    <?php
    add_action('wp_footer', 'disable_line_break_on_textarea', 99);
    function disable_line_break_on_textarea(){ 
    ?>
    <script>
     document.onkeypress = function(evt) {
      if(evt.target.toString() == '[object HTMLTextAreaElement]' && evt.charCode === 13){
       evt.preventDefault();
       return;
      }
     };
    </script>
    <?php }

    2- to strip HTML tags from textarea.

    <?php
    add_filter( 'forminator_prepared_data', 'wpmudev_strip_textarea_html', 10, 2 );
    function wpmudev_strip_textarea_html( $prepared_data, $module_object ){
    	if( $module_object->id != 2235 ){
    		return $prepared_data;
    	}
    
    	foreach( $prepared_data as $key => $value ){
    		if(	strpos( $key, 'textarea' ) !== false ){
    			if( $value ){
    				$prepared_data[ $key ] = wp_strip_all_tags( $value );
    			}
    		}
    	}
    
    	return $prepared_data;
    }

    Please change the form ID from 2235 to your form’s ID.

    Kind regards,
    Zafer

    Thread Starter Zougou

    (@zougou)

    Hi @wpmudevsupport15,

    Thanks a lot for your reactivity, your snippets did the job ??
    Best regards,
    Christelle

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Textarea – disable line breaks’ is closed to new replies.