CodeIgniter Forums

Full Version: Strtoupper
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

Which are the best practice to save a input field as upper string? I tried setting strtoupper in validation rules but does nothing....
Let's say you have 2 input fields: 'city' and 'country'. You want to save both fields in uppercase in the 'cities' table.

Controller:
PHP Code:
$data = array(
 
  'city' => strtoupper($this->input->post('city')),
 
  'country' => strotupper($this->input->post('country'))
);
$this->db->insert('cities'$data); 
Hi Wouter60, 

Thanks for reply. Yah, that code works. I have that way! I was looking for some clean code [best practices].

I think that in the validation rules will be better, so can be shared in all controller methods.... It's not supposed to validation rules run native PHP functions? trim works just fine, but strtoupper no....

(08-26-2019, 12:25 PM)Wouter60 Wrote: [ -> ]Let's say you have 2 input fields: 'city' and 'country'. You want to save both fields in uppercase in the 'cities' table.

Controller:
PHP Code:
$data = array(
 
  'city' => strtoupper($this->input->post('city')),
 
  'country' => strotupper($this->input->post('country'))
);
$this->db->insert('cities'$data); 
(08-27-2019, 01:01 AM)jesuscampos Wrote: [ -> ]trim works just fine, but strtoupper no....

Curious, it is supposed to work. Show the "set_rules" code you have tried.