validation - How can I validate a file upload field in TYPO3? -


i want validate file input field in typo3 seems notempty annonation not work on property of type filereference:

/**  * image  *   * @var \typo3\cms\extbase\domain\model\filereference  * @validate notempty  */ protected $image;  /**  * returns image  *   * @return \typo3\cms\extbase\domain\model\filereference $image  */ public function getimage() {     return $this->image; }  /**  * sets image  *   * @param \typo3\cms\extbase\domain\model\filereference $image  * @return void  */ public function setimage(\typo3\cms\extbase\domain\model\filereference $image) {     $this->image = $image; } 

and simple fluid mark-up:

<f:render partial="formerrors" arguments="{field: 'data.image'}" /> <f:form.upload property="image" /> 

so if try submit empty upload form following error message, because filereference still null:

exception while property mapping @ property path "":php catchable fatal error: argument 1 passed fox\example\domain\model\data::setimage() must instance of typo3\cms\extbase\domain\model\filereference, null given...

ok had error in model setter image property :o ... pgampe said if have trouble fileupload take @ awesome example: github.com/helhum/upload_example , if want add validation on upload input add validate annotation image property, works charm :)

/**  * image  *   * @var \typo3\cms\extbase\domain\model\filereference  * @validate notempty  */ protected $image; 

i have changed:

/**  * sets image  *   * @param \typo3\cms\extbase\domain\model\filereference $image  * @return void  */ public function setimage(\typo3\cms\extbase\domain\model\filereference $image) {     $this->image = $image; }} 

to

/**  * sets image  *   * @param \typo3\cms\extbase\domain\model\filereference $image  * @return void  */ public function setimage($image) {     $this->image = $image; } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -