Form Validation and a Edit Form

#1
[eluser]Glazz[/eluser]
Hello,

I have a form where i have a lot of inputs that goes from the customer firstname to the customer password..

Well, i'm using the form validation library to validate my form inputs, it is working but i have one problem and i think the form library does'nt support this..

The password input when editing a customer is not required but if filled need to be validated, how can i do this, if i can... ?

The rule i use when creating the customer is:
Code:
trim|required|min_length[4]|max_length[20]
I know i don't need to use the required, since i'm using the min_length

I can create a callback but there is another way ?



Edit: I found the problem, i guess.

Since i'm using trim, if the input goes empty the value gets '' and not null since the form validation uses is_null it was not working properly...

Code:
if ( ! in_array('required', $rules) AND is_null($postdata))


I think this needs to be changed, since trim is a nice function, at least for me..

#2
[eluser]LifeSteala[/eluser]
I get around this by adding a IF statement checking to see if there was any POST data for the password field. If so, apply validation rules.

See below which works for me.

Code:
$this->form_validation->set_rules('name', 'Name', 'required|trim|xss_clean');
$this->form_validation->set_rules('email', 'Email', 'required|trim|xss_clean|valid_email');

if ($this->input->post('password'))
{    
  $this->form_validation->set_rules('password', 'Password', 'required|trim|xss_clean|max_length[32]');
  $this->form_validation->set_rules('confirm_password', 'Confirm Password', 'required|trim|xss_clean|matches[password]|max_length[32]');
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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