Welcome Guest, Not a member yet? Register   Sign In
Form validation add custom validation rule not set on a field ?
#1

[eluser]Rushino[/eluser]
Hello,

I was wondering if its possible to add custom validation rule not set on a field but on the whole form ?

Like checking if the username and password is okay, checking if the account is not blocked ?

How would you set the rules ?

Thanks.
#2

[eluser]toopay[/eluser]
callback function : Callbacks: Your own Validation Functions
#3

[eluser]4ever[/eluser]
[quote author="toopay" date="1305804872"]callback function : Callbacks: Your own Validation Functions[/quote]

I've seen the link. I am just wondering why they put the validation rules to controller instead model.

My controller's method:

Code:
function create_member(){      
   $this->load->model("auth_model");
   $this->auth_model->newMemberValidate(1); // checking signup_form input data  

   if ($q = $this->auth_model->newMemberCreate()) { // adding data
      $data['main_content_page'] = 'includes/signup_successful';
      $this->load->view("includes/template", $data);
   }      
  }

Clear...

And the model:

Code:
function newMemberValidate($variant){
  switch ($variant):
  case 1:  
     $this->load->library("form_validation");
     $this->form_validation->set_rules("name", "Name", "trim|required");
     $this->form_validation->set_rules("surname", "SurName", "trim|required");
     $this->form_validation->set_rules("email","Email address", "trim|required|valid_email");
     $this->form_validation->set_rules("username", "User Name", "trim|required|min_length[2]|max_length[20]");
     $this->form_validation->set_rules("psw", "Password", "trim|required|min_length[4]|max_length[32]");
     // special rule: matches[password]
     $this->form_validation->set_rules("psw2", "Password Confirmation", "trim|required|min_length[4]|max_length[32]|matches[psw]");
     $data['main_content_page'] = 'includes/forms/signup_form';
  break;
  endswitch;  
  if ($this->form_validation->run() == false ) die(validation_errors('<p class="error">')."</p>");
  }


I've just have idea to make a method using the "Setting Rules Using an Array" from config, but I would like to configure like this:

Code:
$config = array(
               array( 'username', 'Username', 'trim|required' ),
               array( 'password', 'Password', 'required' ),
               array( 'passconf', 'Password Confirmation', 'required|match[password]'),  
               array( 'email', 'Email','trim|required')
            );

and then to make method which will transform that to the format as in the "Setting Rules Using an Array" section.




Theme © iAndrew 2016 - Forum software by © MyBB