![]() |
how to do unique validation, CodeIgniter2 + Doctrine2 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: how to do unique validation, CodeIgniter2 + Doctrine2 (/showthread.php?tid=50742) |
how to do unique validation, CodeIgniter2 + Doctrine2 - El Forum - 04-06-2012 [eluser]xjermx[/eluser] I am working with CodeIgniter2.1.0/Doctrine2.1.1 I have a registration form, and I want to check to be sure that any email address entered is unique. I have tried this: Code: $this->form_validation->set_rules('email', 'E-mail', Which returns: Quote:A PHP Error was encountered I have also tried following the example on the form_validation page in the user guide for CI: Code: $this->form_validation->set_rules('email', 'E-mail', 'callback_email_check'); This gives me: Quote:Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '[email protected]' for key 'email_index'' in /../applicationFolder/libraries/Doctrine/DBAL/Statement.php:131 Stack trace: #0 /../applicationFolder/libraries/Doctrine/DBAL/Statement.php(131): PDOStatement->execute(NULL) #1 /../applicationFolder/libraries/Doctrine/ORM/Persisters/BasicEntityPersister.php(239): Doctrine\DBAL\Statement->execute() #2 /../applicationFolder/libraries/Doctrine/ORM/UnitOfWork.php(896): Doctrine\ORM\Persisters\BasicEntityPersister->executeInserts() #3 /../applicationFolder/libraries/Doctrine/ORM/UnitOfWork.php(304): Doctrine\ORM\UnitOfWork->executeInserts(Object(Doctrine\ORM\Mapping\ClassMetadata in /../applicationFolder/libraries/Doctrine/DBAL/Statement.php on line 131 What am I doing wrong? Are either of these 'correct'? Is there just something I'm missing to make one or both work? Is there a better way to go about this? how to do unique validation, CodeIgniter2 + Doctrine2 - El Forum - 04-06-2012 [eluser]xjermx[/eluser] Well I've found a solution. I'm not sure if its the best or most elegant, but it works. Code: $this->form_validation->set_rules('email', 'E-mail', Code: public function email_check($str) Still open to anyone offering opinions on how this might be done better! |