• Resolved wilfredw92

    (@wilfredw92)


    Is there any way to make a text field of a form be stored as uppercase in the submissions?

    I saw the?related post?but I’m not fully understand to install the PHP code. After I create the mu-plugins directory, what is the .PHP file name? I can name it randomly? Or there is a specific name for the .PHP file. And, is the PHP code still works on latest version of the plugin?

    Thanks in advance!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter wilfredw92

    (@wilfredw92)

    Ok. I figured it out to install it. But, it seems doesn’t work for field group repeat, only works on 1st field group.

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @wilfredw92

    I hope you’re well today!

    That’s due to how repeater works and the fact that JS won’t be applied to directly (unless it would be significantly expanded/changed) after the form is already rendered, to the elements that are “injected”.

    But we can use a different method which would be a combination of CSS (to handle front-end display) and PHP (to handle submission data).

    You’d need to remove solution that you added entirely first and then add this code as MU plugin to the site:

    <?php 
    
    // set upper-case display on front
    add_action( 'wp_footer', 'forminator_uppercase_text_style', 99 );
    function forminator_uppercase_text_style() { 
    	?>
    	<style>
    		.forminator-field-text input {
    			text-transform:uppercase;
    		}
    	</style>
    	<?php 
    }
    
    // convert for submission
    
    add_filter( 'forminator_field_text_sanitize', 'forminator_uppercase_text_submit', 11, 2 );
    function forminator_uppercase_text_submit( $data, $field ) {
    	
    	if ( $field['type'] == "text" ) { 
    		$data = strtoupper( $data );
    	}	
    	return $data;
    }

    Here’s how to add it:

    1. create an empty file with a .php extension (e.g. “forminator-uppercase-text-fields.php”) in the “/wp-content/mu-plugins” folder of your site’s WordPress install

    2. copy above code and paste it into that file

    3. save the file.

    This will work regardless of whether form is loaded using AJAX or no-AJAX and will handle all the text (“input” type) fields on the form – including paged forms and repeaters.

    The only “catch” here is it will apply to all the forms on site. If you want to make it limited to specific forms, let us know.

    Kind regards,
    Adam

    Thread Starter wilfredw92

    (@wilfredw92)

    Hi Adam,

    Thanks for the help. However, the following field group names remain unchanged in uppercase on the submission data.

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @wilfredw92

    Thanks for response!

    Assuming those are group/repeater fields it should work just fine. I’ve tested code before sharing so I’m sure that it’s correct – unless I missed some specific case (e.g. some specific type of form/field configuration), which is actually entirely possible.

    Would you mind sharing export of your form with us so we could test it directly?

    To share form export:

    – go to “Forminator -> Forms” page in site’s back-end
    – click on a little “gear” icon next to the form in question
    – use “Export” link from the drop-down menu
    – and put export code at https://pastebin.com
    – then share direct link to it in response below.

    This way will be able to import form into test setup, text everything and provide modified code if necessary.

    Note: form export does not include any credentials such as e.g. PayPal or Stripe and other and it does not include submitted data; it’s only a form itself; the rest stays safely within your site.

    Best regards,
    Adam

    Thread Starter wilfredw92

    (@wilfredw92)

    Hi Adam,

    Maybe my name field is not a general text input field? Name field shows {name-1} instead of {text-1}.

    Btw, here is the link for the form export code: https://pastebin.com/7r5i2fwF

    Thanks

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @wilfredw92

    Thanks for response!

    Yes, “name-1” is not a “text” field. I mean, technically speaking it is but in terms of Forminator terminology when we say “text” fields we are referring to fields like {text-1}, {text-2} and so on – basically, fields of type “input”.

    To make also name fields uppercase, do this changes to the code that I shared previously:

    1. Replace this

    .forminator-field-text input {
    			text-transform:uppercase;
    		}

    with this

    .forminator-field-text input,
    .forminator-field-name input {
    			text-transform:uppercase;
    		}

    2. and this

    if ( $field['type'] == "text" ) {

    with this

    if ( ( $field['type'] == "text" ) || ( $field['type'] == "name" ) ) {

    Best regards,
    Adam

    Thread Starter wilfredw92

    (@wilfredw92)

    Hi Adam,

    The following field group names still remain unchanged on the submission data. Kindly check my .php codes below.

    <?php 
    
    // set upper-case display on front
    add_action( 'wp_footer', 'forminator_uppercase_text_style', 99 );
    function forminator_uppercase_text_style() { 
    	?>
    	<style>
    		.forminator-field-text input,
            .forminator-field-name input {
    			text-transform:uppercase;
    		}
    	</style>
    	<?php 
    }
    
    // convert for submission
    
    add_filter( 'forminator_field_text_sanitize', 'forminator_uppercase_text_submit', 11, 2 );
    function forminator_uppercase_text_submit( $data, $field ) {
    	
    	if ( ( $field['type'] == "text" ) || ( $field['type'] == "name" ) ) {
    		$data = strtoupper( $data );
    	}	
    	return $data;
    }

    Thanks

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @wilfredw92

    Can you please replace the code and use this one instead?

    <?php
    
    // set upper-case display on front
    add_action('wp_footer', 'forminator_uppercase_text_style', 99);
    function forminator_uppercase_text_style()
    {
    ?>
    	<style>
    		.forminator-field-text input,
    		.forminator-field-name input {
    			text-transform: uppercase;
    		}
    	</style>
    <?php
    }
    
    // convert for submission
    add_filter('forminator_field_name_sanitize', 'forminator_uppercase_text_submit', 11, 2);
    add_filter('forminator_field_text_sanitize', 'forminator_uppercase_text_submit', 11, 2);
    function forminator_uppercase_text_submit($data, $field)
    {
    
    	if (($field['type'] == "text") || ($field['type'] == "name")) {
    		$data = strtoupper($data);
    	}
    	
    	return $data;
    }

    Let us know the result you got.
    Best Regards
    Patrick Freitas

    Thread Starter wilfredw92

    (@wilfredw92)

    Hi Patrick,

    It works! Thanks Patrick.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Make a text field data as uppercase’ is closed to new replies.