The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Force a text field convert case after submission

Labels

This Discussion is public

Notifications

Hi, I'd like to specifically force some fields to Convert Case mode when user submits an entry, for example:

john philip mason to John Philip Mason

I found an example in knowledgebase/frm_validate_field_entry/#kb-capitalize-all-text-fields, where I can change the mb_strtoupper function to mb_convert_case.

The problem is that example works with all text fields, and I want to apply the function only to some fields.

Thanks in advance.

Hi Julius,
You can check field id or key (recommended) in the condition.

Replace 'key1', 'key2', .... with field keys of fields that you want to convert.

add_filter('frm_validate_field_entry', 'field_caps_validation', 8, 3);
function field_caps_validation($errors, $posted_field, $posted_value){
if (in_array($posted_field->field_key, array('key1', 'key2', 'key3') ) ) {
$_POST['item_meta'][$posted_field->id] = mb_strtoupper($posted_value);
}
return $errors;
}

Thanks, and I suppose that I only have to substitute the mb_strtoupper with mb_convert_case in your code, right?

I will try this in the corresponding line:

$_POST['item_meta'][$posted_field->id] = mb_convert_case($posted_value, MB_CASE_TITLE, "UTF-8");

Yes, you are right

Yes, it works. Thanks again!

Discussion closed.