Frontend\Modules\Profiles\Actions\ChangeEmail::validateForm PHP Method

validateForm() private method

Validate the form.
private validateForm ( )
    private function validateForm()
    {
        // is the form submitted
        if ($this->frm->isSubmitted()) {
            // get fields
            $txtPassword = $this->frm->getField('password');
            $txtEmail = $this->frm->getField('email');
            // password filled in?
            if ($txtPassword->isFilled(FL::getError('PasswordIsRequired'))) {
                // password correct?
                if (FrontendProfilesAuthentication::getLoginStatus($this->profile->getEmail(), $txtPassword->getValue()) !== FrontendProfilesAuthentication::LOGIN_ACTIVE) {
                    // set error
                    $txtPassword->addError(FL::getError('InvalidPassword'));
                }
                // email filled in?
                if ($txtEmail->isFilled(FL::getError('EmailIsRequired'))) {
                    // valid email?
                    if ($txtEmail->isEmail(FL::getError('EmailIsInvalid'))) {
                        // email already exists?
                        if (FrontendProfilesModel::existsByEmail($txtEmail->getValue(), $this->profile->getId())) {
                            // set error
                            $txtEmail->setError(FL::getError('EmailExists'));
                        }
                    }
                }
            }
            // no errors
            if ($this->frm->isCorrect()) {
                // update email
                FrontendProfilesModel::update($this->profile->getId(), array('email' => $txtEmail->getValue()));
                // trigger event
                FrontendModel::triggerEvent('Profiles', 'after_change_email', array('id' => $this->profile->getId()));
                // redirect
                $this->redirect(SITE_URL . FrontendNavigation::getURLForBlock('Profiles', 'ChangeEmail') . '?sent=true');
            } else {
                $this->tpl->assign('updateEmailHasFormError', true);
            }
        }
    }