Welcome Guest, Not a member yet? Register   Sign In
trim all values on database insert?
#1

[eluser]Brad K Morse[/eluser]
Is there a CI db function that automatically trims white space at the beginning and ending of each value before it inserts into the database?

Instead of having to wrap each value in trim, ex:
Code:
trim($this->input->post('username'));
#2

[eluser]solid9[/eluser]
Isn't it the "Active Records" is already doing this?
(Correct me if I'm wrong.)

Or experiment it with 'Active Records'.
#3

[eluser]Aken[/eluser]
No, there's no existing function that will automatically trim values before entering the DB. You'll need to do that yourself. If you're using the form validation library, consider adding "trim" to your field rules.
#4

[eluser]tpetrone[/eluser]

IF your using validation on the $_POST values then via validation you could trim as well.

Based on the user guide, this should workd

Code:
$this->form_validation->trim($value)

or

$this->form_validation->set_rules('your_value', 'trim|required|etc|etc');

check out the Form Validation class in the users guide

#5

[eluser]Aken[/eluser]
Code:
$this->form_validation->trim()

This is invalid. it is never a method of the library. If you include it in your rules, it will call the native trim() function by itself. Same for any other one-required-parameter function (stripslashes, htmlentities, etc.).




Theme © iAndrew 2016 - Forum software by © MyBB