• Resolved wiltschek

    (@wiltschek)


    Hi,

    this is a great plugin!
    I noticed that MailChimp cuts off text at 255 characters. So I’d like to limit the text users can write to 255 characters, so they at least know that it won’t be seen.

    How would I go about doing this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @wiltschek,

    Using a filter, you can add a maxlength attribute to your text fields which will force the input to be 255 characters or shorter.

    This filter function will do that:

    // Add a maxlength to an input field
    add_filter( 'yikes-mailchimp-field-data', 'yikes_easy_forms_text_field_max_length', 10, 3 );
    
    function yikes_easy_forms_text_field_max_length( $field_array, $field, $form_id ) {
    	if ( $field['type'] === 'text' ) {
    		$field_array[] = 'maxlength="255"';
    	}
    
    	return $field_array;
    }

    Will that work for you?

    Let me know.

    Cheers,
    Kevin.

    Thread Starter wiltschek

    (@wiltschek)

    Works like magic! Thanks a lot!

    For people who don’t know how to use filters… I used https://www.ads-software.com/plugins/code-snippets/ and just copied the above code into a new snippet, and then added the “short code” for the snippet on the page.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Restrict input length’ is closed to new replies.