CodeIgniter Forums
Strtoupper - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Strtoupper (/showthread.php?tid=74205)



Strtoupper - jesuscampos - 08-26-2019

Hi,

Which are the best practice to save a input field as upper string? I tried setting strtoupper in validation rules but does nothing....


RE: Strtoupper - Wouter60 - 08-26-2019

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); 



RE: Strtoupper - jesuscampos - 08-27-2019

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); 



RE: Strtoupper - dave friend - 08-27-2019

(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.