⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Form Validation is_unique Problem



Christopher
  • profile picture
  • Member

Posted 07 February 2013 - 15:01 PM

I just started building the admin panel using this awesome library.
 
In this admin panel the admin has the privilege to create & update username of an individual.
Therefore , for validation of an email , I am using CI's form validation library
 
$crud->set_rules('Email','Email','required|'valid_email'|is_unique[User.Email]');

 

The above line of code works well when creating username .
 
The problem occurs when i am UPDATING the same user and when i hit the UPDATE BUTTON I get the following error  "Email field must be unique"
 
As you can guess the form validator is firing the same query when state is 'edit'
 
i also tried using the getState() but it doesn't seems to work
 
$state = $crud->getState();
if($state == 'add'){
   $crud->set_rules('Email','Email','required|is_unique[Employee.Email]');
}

 

Can one suggest me a different approach to solve this .


victor
  • profile picture
  • Member

Posted 07 February 2013 - 15:21 PM

your code is wrong. because when you update you can duplicate the email address. I type a solution later.

Christopher
  • profile picture
  • Member

Posted 08 February 2013 - 05:39 AM

Oh Okay ..Thank U :)


victor
  • profile picture
  • Member

Posted 08 February 2013 - 09:53 AM

/topic/71-solved-set-rules-is-unique-doesnt-work/

Christopher
  • profile picture
  • Member

Posted 08 February 2013 - 13:24 PM

Sorry to bother you  :(, a simple forum search would have fixed the problem. Anyway Thx again :)   :D