Extbase Validator – Errormessages are duplicated

I wrote a validator for a contactform and the problem was that errors were displayed twice. The Controller has a showAction for showing the form:

/**
 * @param Contactform $contactform
 */
public function showAction(	$contactform = null) {
	$this->view->assign('contactform', $contactform);
	$this->view->assign('timestamp', time());
}

with the following template:

<f:form action="create" name="contactform" object="{contactform}" objectname="contactform">
<f:render arguments="{object:contactform}" partial="FormErrors">
<f:form.textfield id="name" name="name" property="name" required="true">
<f:form.textfield id="email" name="email" property="email" required="true">
...

This form is supposed to lead to the createAction, which looks like this:

/**
 * @param Contactform $contactform
 * @validate $contactform \Package\Extension\Domain\Validator\ContactformValidator
 */
public function createAction(Contactform $contactform){
	$contactform->setPid($GLOBALS['TSFE']->id); //set pid to current page ID
	$this->contactformRepository->add($contactform);
	//redirect to thank you page...
}

And the ContactformValidator looks like this:

getName()){
            $this->addError(
                $this->translateErrorMessage(
                    'tx_extension_domain_model_contactform.errors.required',
                    'extension'
                ), 111);
            $isValid = false;
        }

        if(!$contactform->getEmail()){
            $this->addError(
                $this->translateErrorMessage(
                    'tx_extension_domain_model_contactform.errors.required',
                    'extension'
                ), 111);
            $isValid = false;
        }
        return $isValid;
    }
}

This works, except that every error is duplicated. I googled this problem for a long time until finally I discovered this link. The author says that validators, that are named DOMAINNAMEValidator, automatically validate a domain. This means my @validator annotation was obsolete. I removed it and then it worked.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.