I’m very new to CodeIgniter, and I have a question about prepping/purifying/manipulating the input fields. When I say “prepping/purifying/manipulating” fields, I mean:
if an integer field is not entered by the user (leave blank), if user clicks on “submit” it should be set to NULL. ie. $this->input->post(‘integer_field’) should be NULL instead of ‘’ (empty string), so that when saving data to the database, it won’t cause any MySQL error
for example http://ellislab.com/forums/member/edit_userpass is a form which allows you to set the screen name, change the password (only if you enter the new password and confirm new password). When submitting this form without changing the password, both $this->input->post(‘password’) and $this->input->post(‘password_confirm’) will be ‘’ (empty string). So obviously when using the model to save to the database, these two fields shouldn’t be inserted into database and they both need to unset.
So, I’m trying to find out the best place to perform the above tasks, and I think config/form_validation.php will be the best place to do so (form_validation can both validate fields and prepping fields. Also instead of calling form_validation->run in controller I would like to put all of my validations in one place, thus config/form_validation.php), however I have a few concerns:
based on my understanding on system/library/Form_validation.php, rules won’t be called on any field if it’s blank and it’s not a “required” field. So how am I perform #1, if the integer field is not required?
for #2, I think I need to use the “callback” in order to unset $this->input->post(‘password’) and $this->input->post(‘password_confirm’), however, will it screw up any of the code in Form_validation.php
Also if you think config/form_validation.php is not an appropriate file, which file should be used to prepping/purifying/manipulating fields?