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
Force a text field convert case after submission
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.
September 9, 2018 at 5:39 pm
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;
}
September 9, 2018 at 10:46 pm
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");
September 9, 2018 at 11:12 pm
Yes, you are right
September 9, 2018 at 11:17 pm
Yes, it works. Thanks again!
Discussion closed.