• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Strtoupper

#1
Hi,

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

#2
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); 
Reply

#3
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); 
Reply

#4
(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.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.