Hook custom validation error
martin28
New
Hi again Team,
I'm trying to hook custom login validation error. I managed to throw it as new Exception message and it show's on the lower left corner. Can I hook/throw this same error on the login validation (the one with red background wrapped with div.Messages Errors > ul > li)?
I've search hours on this forum, can't find any.
TIA
0
Comments
Hard to tell without any code from you.
Look at this code, taken from the EntryController:
$this->fireEvent('SignIn'); if ($this->Form->isPostBack()) { $this->Form->validateRule('Email', 'ValidateRequired', sprintf(t('%s is required.'), t(UserModel::signinLabelCode()))); $this->Form->validateRule('Password', 'ValidateRequired'); if (!$this->Request->isAuthenticatedPostBack() && !c('Garden.Embed.Allow')) { $this->Form->addError('Please try again.'); }Instead of throwing an error, I would simply "put" it there.
public function entryController_signIn_handler($sender) { if ($sender->Form->isPostBack() == false) { return; } // Do the checks with $sender->Form->formValues() if ($failed == true) { $sender->Form->addError('This should be a meaningful message.', 'Your Additional Field'); } }Thanks again @R_J , I indeed managed to add custom error using the condition on $sender->Form->formValues().
You rock!