[TYPO3-mvc] Empty page after validation

Patrik Lang info at patrik-lang.de
Tue Jun 15 16:40:05 CEST 2010


Hi *,

I have validators for own models such as a user model extending
FrontendUserModel and a own model handling files.

When I fill out the user form (or better do NOT fill out the form to test
the validation), the validator validates for example:
- no password entered
- no username entered
- username must have at least 6 characters
- ...

And reloads the form and displays the errors correctly.

Now I tried this with my file validator. When I now do NOT fill out the
form, I get an empty page. In backend as in frontend.

When I debug the validator and output the error attribute $this->errors,
there are errors available like in the user validator.

I have a special in my validators because I want to add FieldPropertyErrors
which are not available in the own Validators by default. So I wrote a Main
Validator with a method getting the field name and error code which adds an
Tx_Extbase_Validation_
PropertyError and fills it with the needed Tx_Extbase_Validation_Error, so I
have a message and the class f3-form-error on my fields.

Here's my validators:

MainValidator:

---snip---
class Tx_Libextbase_Domain_Validator_MainValidator extends
Tx_Extbase_Validation_Validator_AbstractValidator {

    protected $fieldErrors = array();

    protected $propertyErrors = array();

    public function isValid($value) {
    }

    protected function addFieldError($field, $code, $onlyField = false) {
        $dummyError[0] =
t3lib_div::makeInstance('Tx_Extbase_Validation_Error',
Tx_Extbase_Utility_Localization::translate('be_user_error_dummy',
'Xchange'), 0);

        if($onlyField) {
            $index = count($this->propertyErrors);
            $this->propertyErrors[$index] =
t3lib_div::makeInstance('Tx_Extbase_Validation_PropertyError', $field);
            $this->propertyErrors[$index]->addErrors($dummyError);
        } else {
            $index = count($this->propertyErrors);
            $this->fieldErrors[] =
t3lib_div::makeInstance('Tx_Extbase_Validation_Error',
Tx_Extbase_Utility_Localization::translate('be_user_error_'.$field.'_'.$code,
'Xchange'), $code);
            $this->propertyErrors[$index] =
t3lib_div::makeInstance('Tx_Extbase_Validation_PropertyError', $field);
            $this->propertyErrors[$index]->addErrors($this->fieldErrors);
        }
    }
}
---snip---

FileValidator:

---snip---
class Tx_Xchange_Domain_Validator_FileValidator extends
Tx_Libextbase_Domain_Validator_MainValidator {

    /**
    * @param Tx_Xchange_Domain_Model_File $file
    */
    public function isValid($file) {
        $tempUid = $file->getUid();

        if(empty($tempUid)) {
            $tempFileName = $file->getFileName();

            if(empty($tempFileName)) {
                $this->addFieldError('name', 1221560718);
            } else {
                $fileRepository =
t3lib_div::makeInstance('Tx_Xchange_Domain_Repository_FileRepository');
                $existingFile =
$fileRepository->findOneByFileName($tempFileName);

                if($existingFile instanceOf Tx_Xchange_Domain_Model_File &&
$file->getCopyReplace() == '') {
                    $this->addFieldError('name', 1234567890);
                }
            }
        }

        if(count($this->propertyErrors)) {
            $this->errors = $this->propertyErrors;
        }

        return count($this->getErrors()) === 0;
    }
}
---snip---

I hope this is explained enough. If not, let me know and I try to explain
more.

Greets
Patrik


More information about the TYPO3-project-typo3v4mvc mailing list