是否可以为允许的文件类型(仅在我的示例中为* .pdf)和最大文件大小(在我的示例中最大为5mb)验证typo3(例如7.6.23)表单?也许有规则功能?
我的表单如下:
enctype = multipart/form-data
method = post
prefix = tx_form
confirmation =
postProcessor {
1 = mail
1 {
recipientEmail = xxx@xxx.de
senderEmail = formmailer@xxx.de
subject = email subject
}
}
...
40 = FIELDSET
40 {
20 = FILEUPLOAD
20 {
type = file
name = Anschreiben
label {
value = Anschreiben
}
}
}
...
rules {
1 = required
1 {
showMessage =
message = Benötigt
error = Dies ist ein Pflichtfeld
element = Vorname
}
2 = required
2 {
showMessage =
message = Benötigt
error = Dies ist ein Pflichtfeld
element = Nachname
}
3 = email
3 {
showMessage =
message = (max.muster@domain.com)
error = Dies ist keine gültige E-Mail-Adresse
element = E-Mail
}
}
更新
感谢您将我指向FileAllowedTypesValidator和FileMaximumSizeValidator。
我尝试将这个想法添加到规则中:
rules {
4 = fileallowedtypes
4 {
breakOnError = 0
showMessage =
message = (%allowedTypes)
error = only pdf please!
types = application/pdf
element = Anschreiben
}
5 = filemaximumsize
5 {
breakOnError = 0
showMessage =
message = The file has to be smaller as %maximum
error = file is too big!
maximum = 5242880
element = Anschreiben
}
}
由于我有多个FileUpload-Field,我为每个字段添加了这两个规则。查询现在可以正常工作,当我上传错误的文件类型或大于5 MB的文件时,我收到错误。
唯一的问题是,我不能将FileUpload-Fields留空;我总是得到错误的文件类型"错误。
答案 0 :(得分:0)
你可以使用下面的typoscript。
plugin.tx_form {
settings {
registeredValidators {
fileallowedtypes {
displayName = Allowed mimetypes for file
className = TYPO3\CMS\Form\Domain\Validator\FileAllowedTypesValidator
}
filemaximumsize {
displayName = Maximum size for file (bytes)
className = TYPO3\CMS\Form\Domain\Validator\FileMaximumSizeValidator
}
}
}
}