My application has a simple form with one field (email), which makes it possible to register in the newsletter.
If I enter a new letter, everything works fine. If I enter a letter that already exists in the database, I get the error SQLSTATE [23000]: violation of integrity constraint: 1062 Duplicate record ... Because I defined this field as unique in the database.
All I want to do is redirect :: back () → from ("message", "letter has already been registered") But I do not know how I can do this? Can I just put an if statement in a method controller? Or I have to define it in $ rules in the model by adding another rule:
public static $rules = array( 'email' => 'required',);
Thanks!
source share