[Forminator Pro] Is there a way to restrict a text message box to just plain text and not accept H

We received a bunch of spam with HTML embeded in the message. 
Is there a way to restrict the form field to only support plain txt and no code?

  • Elijah Shobowale
    • Ex Staff

    Hello Alastair Dodwell

    Hope you are doing great today.

    Yes its possible, we can strip out the html tags before it sends to your email.

    Here is a code snippet on how to go about it for a specific form, and hopefully it will help:

    <?php
    
    function forminator_strip_html_from_email( $front_mail, $custom_form, $data, $entry ) {
    $form_id = 25282;
      if((int)$custom_form->id === $form_id ){
    
        add_filter(
          'wp_mail',
          function( $args ) {
            remove_filter( 'forminator_custom_form_mail_before_send_mail', 'forminator_strip_html_from_email', 9 );
            $args[ 'message' ] = wp_strip_all_tags( $args[ 'message' ] );
            return $args;
          }
        );
    
      }
    
    }
    
    add_filter( 'forminator_custom_form_mail_before_send_mail', 'forminator_strip_html_from_email', 9, 4 );

    Just replace 25282 to your custom form ID.

    To get your form ID, on the Edit Form Page, you will see the form in your URL. See screenshot below:

    [attachments are only viewable by logged-in members]

    You can add the snippet above in a mu-plugin. If you are not familiar with mu-plugins you can read about them here : https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    The snippet I provided above only strips out the html tags from the email body of the email notifications that Forminator sends.

    In case you want it on all your forms, simply remove the If condition or if it is for more forms we would just need to create a small update.

    I would strongly recommend to first try this out on a staging/testing site before applying on production site.

    Let us know if this work for you now.

    Warm Regards,
    Elijah