Search code examples
wordpressuppercasegravity-forms-plugin

a different character appears when converting lowercase "i" to uppercase "İ" (Wordpress Gravity)


I am using a function.php code to convert all characters to uppercase when posting the "input" data for the Wordpress gravity forms plugin.

add_action('gform_pre_submission_1', 'capitalize_fields_1');
function capitalize_fields_1($form){
// add all the field IDs you want to capitalize, to this array
$fields_to_cap = array('input_1');
        foreach ($fields_to_cap as $each) {
                // for each field, convert the submitted value to uppercase and assign back to the POST variable
                // the rgpost function strips slashes
                
                $_POST[$each] = strtoupper(rgpost($each));
        }
        // return the form, even though we did not modify it
        return $form;
}

However, I am using Turkish language and there is a character that is outside of UTF-8. The lowercase letter "i" becomes the letter "I" when converting. These two characters mean different things from each other. I want to convert the lowercase letter "i" into letter "I".

I found a php code for this process, but I could not adapt it to the function.php file.

function mb_strtoupper_tr($metin){
    $metin=str_replace('i', 'İ', $metin);

Can anyone help me how to adapt this or implement a more efficient method?


Solution

  • add_action('gform_pre_submission_1', 'capitalize_fields_1');
    function capitalize_fields_1($form){
    // add all the field IDs you want to capitalize, to this array
    $fields_to_cap = array('input_1');
            foreach ($fields_to_cap as $each) {
                    // for each field, convert the submitted value to uppercase and assign back to the POST variable
                    // the rgpost function strips slashes
                    
                    $_POST[$each] = strtoupper(str_replace('i', 'İ', rgpost($each)));
            }
            // return the form, even though we did not modify it
            return $form;
    }