Jump to content

Form error showing not showing


arog

Recommended Posts

Hi

I made a override for the customerform validate function

I check two custom field and display a error or not.

The things is when I fill correctly the second field (cse) and not the first one (matricule), I see zero error on the form

When I fill them both incorrectly, then I see both error...

When I just fill the second one (cse) incorrectly, I see the error for the field.

This is very annoying. 

Please can someone help ?

Here is the code

public function validate()
    {
        $bool1 = true;
        $bool2 = true;

        // Matricule check
        if (($matriculeCode = $this->getField('matricule')) && $matriculeCode->isRequired()) {
    
            $matriculeValue = $this->getValue('matricule');
            $query = 'my sql query';

            if ($result = Db::getInstance()->ExecuteS($query)) {
                    $bool1 = true;
            }
            else {
                $matriculeCode->addError(sprintf(
                    $this->translator->trans(
                        'Code matricule non valide!', [], 'Shop.Forms.Errors'
                    )
                ));
                $bool1 = false;
            }
        }

        // CSE CHECK
        if (($cseCode = $this->getField('code_creuch')) && $cseCode->isRequired()) {
            
            $cseCodeValue = $this->getValue('code_creuch');
            $query = 'my sql query';
            
            if ($result = Db::getInstance()->ExecuteS($query)) {
                $bool2 = true;
            }
            else {
                $cseCode->addError(sprintf(
                    $this->translator->trans(
                        'Code CSE non valide!', [], 'Shop.Forms.Errors'
                    )
                ));
                $bool2 = false;
            }
        }

        if ($bool1 == true && $bool2 == true) {
            $is_valid = true;
        }
        else {
            $is_valid = false;
        }

        return parent::validate();
    }

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...