Discussion:
[TYPO3-english] Typo3Script Form with multiple FileUploads and fileallowedtypes/filemaximumsize
Marc Grube
2017-11-10 15:27:54 UTC
Permalink
Hello,

i would like to have a form in typoscript, in which the user has the option to either upload up to six files, or no file. The files have to be in *.pdf-filetype with a maximum filesize of 5MB.

My code looks like this:

enctype = multipart/form-data
method = post
prefix = tx_form
confirmation =
postProcessor {
1 = mail
1 {
recipientEmail = test (at) test.de
senderEmail = test (at) test.de
subject = Betreff
}
2 = redirect
2 {
destination = 250
}
}
10 = FIELDSET
10 {
legend {
value = Ihre Kontaktdaten
}
10 = TEXTLINE
10 {
type = text
name = Vorname
label {
value = Vorname
}
}
20 = TEXTLINE
20 {
type = text
name = Nachname
label {
value = Nachname
}
}
30 = TEXTLINE
30 {
type = text
name = E-Mail
label {
value = E-Mail Adresse
}
}
40 = TEXTLINE
40 {
type = text
name = Telefon
label {
value = Telefon
}
}
}
..
40 = FIELDSET
40 {
10 = HEADER
10 {
class = content-header
headingSize = h4
content = Überschrift
}
20 = FILEUPLOAD
20 {
type = file
name = datei1
label {
value = Anschreiben
}
}
30 = FILEUPLOAD
30 {
type = file
name = datei2
label {
value = Lebenslauf
}
}
..
}
60 = SUBMIT
60 {
type = submit
name = 15
value = Formular absenden
}
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 (at) domain.com)
error = Dies ist keine gültige E-Mail-Adresse
element = E-Mail
}
4 = fileallowedtypes
4 {
breakOnError = 0
showMessage =
message = (%allowedTypes)
error = Bitte hängen Sie nur Dokumente mit dem Dateityp *.pdf an.
types = application/pdf
element = datei1
}
5 = filemaximumsize
5 {
breakOnError = 0
showMessage =
message = The file has to be smaller as %maximum
error = Diese Datei ist zu groß (max 5MB).
maximum = 5242880
element = datei1
}
6 = fileallowedtypes
6 {
breakOnError = 0
showMessage =
message = (%allowedTypes)
error = Bitte hängen Sie nur Dokumente mit dem Dateityp *.pdf an.
types = application/pdf
element = datei2
}
7 = filemaximumsize
7 {
breakOnError = 0
showMessage =
message = The file has to be smaller as %maximum
error = Diese Datei ist zu groß (max 5MB).
maximum = 5242880
element = datei2
}
..
}

Everything works so far, the only problem I have that the user cant send the form without uploading a file, I always get the "wrong filetype" error in that case. How can I adjust the form, so that the fileallowedtypes-function only gets called, when one or more fileuploads are made?

Best regards and thank you in advance!

Loading...