[TYPO3-mvc] validator too greedy, conditional validation?

Andrea Schmuttermair abo at schmutt.de
Fri Sep 6 11:39:06 CEST 2013


You could add a hidden field, and set the value to 1 at submit of an  
upload, for example by javascript at "Submit"?

Or just check if there is a upload file, if yes do your operation, if  
not skip.

  public function isValid($value) {
     $this->errors = array();

     if (isset($_FILES['tx_myext_file'])) {
       ...do your upload stuff
     }

     if (count($this->errors) > 0) {
       return false;
     }

     return true;
  }

If there are too much problems, a redesign of your  
Controller/Action/Validator logic might be usefull.
Upload operations in the validator are not the idea of validation.
In the Controller, you can add another Action "uploadAction" and  
redirect from one action to another, depending on the upload status:

if ($thereWasAnUpload) {
              
$this->redirect('upload','controllername','myext',array('params' =>  
$params);
         } else {
             ...
         }

Best regards,
Andrea

Quoting Gerhard Mehsel <sparking at gmx.net>:

> Hello,
>
> I have an extbase plugin that is inserted on a page two times. Each  
> plugin has some form fields and both forms are sent to the same  
> createAction in controller (it's the same plugin with different form  
> fields) and so both forms share the same validator annotations.
>
> Since the second plugin has upload form fields it needs to have a  
> validator for uploads (filesize, file extension, successful upload,  
> ...). The first plugin does not need this validator.
>
> If the second form is sent, the validators of the createAction are  
> called twice - once for the first plugin (that is not sent) and once  
> for the second plugin.
>
> Since the upload validator does the upload stuff also and moves the  
> uploaded temporary file to its destination, there is no longer a  
> temporary file for the second call of the validator and therefore it  
> can never be valid.
>
> A solution would be to somehow distinguish between the first and the  
> second call in validator and do the upload stuff only when really  
> needed.
>
> Is there a possibilty to do a conditional validation in any way?
>
> Best regards,
> Gerd
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc





More information about the TYPO3-project-typo3v4mvc mailing list