Please upgrade here. These earlier versions are no longer being updated and have security issues.

Hook custom validation error

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

Comments

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator
    edited July 2018

    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');
        }
    }
    


    Bleistivt
  • Thanks again @R_J , I indeed managed to add custom error using the condition on $sender->Form->formValues().
    You rock!

Sign In or Register to comment.