添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hey guys. how to handle this erro SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
actually this constraint set in the mysql side want to show this error message in bottom of fields but cakephp throw this error whole screen… please tell me how to handle this error validation in well form.
Screenshot from 2023-06-09 11-49-30 1678×939 123 KB

i wan this return me as text form message like ‘this is E-mail already in used’ please help me guys

thank for reply @KevinPfeifer and i had already read docs but stack with same error…

my mode side code:-

$validator
->email(‘email’)
->requirePresence(‘email’, ‘create’)
->notEmptyString(‘email’)
->add(‘email’, ‘unique’, [‘message’ => ‘this Email Already in Use’, ‘rule’ => ‘validateUnique’, ‘provider’ => ‘table’]);

public function buildRules(RulesChecker $rules): RulesChecker
$rules->add($rules->isUnique([‘email’]), [‘errorField’ => ‘email’]);
return $rules;

please help me, let me show you image what i want, i want to show error near the Email field in form

Screenshot from 2023-06-09 16-26-11 1678×943 39.5 KB
public function buildRules(RulesChecker $rules): RulesChecker
    $rules->add($rules->isUnique(['email']), ['errorField' => 'email']);
    return $rules;

you shouild already get what you want.

The code

->add('email', 'unique', [ ... ]);

inside your validator is not needed.

yes @KevinPfeifer i have already done it but I am still getting same error… SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘[email protected]’ for key ‘email’.

this is another app and it work fine but i am working with different project
Screenshot from 2023-06-09 16-26-111678×943 39.5 KB Actually Mysql developer has set unique email constraint therefore I got this error when same error

First of all tell me that… are you using any plugin in your project? if yes you have plugin then you have to do some configuration before save or anything else you want to do. so please make you are you using plugin or not after that i will help you @daryl .
because you already define validation rules even @KevinPfeifer already suggest you perfect code and solution with example so it would be work