Forums

Convert field to uppercase

momentis 04 Nov, 2015
Is there a way to have text fields on a form automatically convert to all uppercase once a user exits the field, saving to the database in all caps?

Thanks!
Rick
GreyHead 04 Nov, 2015
Hi Rick,

This is simple to do after the form submits. Is that OK or do you need to do it in the browser?

For the after submit version
<?php
$elements = array(
  'input_name_a',
  'input_name_b',
  . . .
);
foreach ( $elements as $e ) {
  $form->data[$e] = strtoupper($form->data[$e]);
} 
?>

Bob
momentis 04 Nov, 2015
No, I don't need it in the browser at all. Just in the table. So will this code work for all fields on the form, or do I somehow have to add lines for each text field?
GreyHead 04 Nov, 2015
Hi Rick,

If there are no exceptions you can use this
<?php
foreach ($form->data as $k => $v ) {
  $form->data[$k] = strtoupper($v);
}
?>
This might cause some unwanted side-effects so check carefully.

Bob
This topic is locked and no more replies can be posted.