File form field marked as required always returns validation error.
It has been reported earlier #12832 but the problem was not solved.
This field type does not contain any value. Problem is in: libraries > src > Form > FormField in line 1201 which checks for value if field is required:
if ($required && (($value === '') || ($value === null)))
Possible solution is to check if this is not file field type eg:
if ($this->element['type'] != 'file' && $required && (($value === '') || ($value === null)))
This solution restores proper functionality. We have front-end verification and can do server-side veryfication with rules.
Create a form with a file field marked as required. Attach a file. Save form.
Success message
Error message saying that the field is not filled in.
Joomla 4.4.9, PHP 7.4.33
Same on 5.2.4
Labels |
Added:
No Code Attached Yet
|
It is irracional to check the value for element that does not return any value. It always fails.
With my suggestion it wont be necessary to create any workarounds, hacks, etc. It will work based on core client-side validation functionality and will skip value check on server-side. It's just a change of one line of code and file field will work fine without any extra code.
I think there might be location error,Locate the File to libraries/src/Form/FormField.php
in your Joomla installation or Find line 1201, which checks if the field is required. Change it to:
if ($this->element['type'] != 'file' && $required && (($value === '') || ($value === null)))
Save and then try!
@ayeshabarlas I have already done this and everything works fine after implementing this change. Now it is good to push this into J! code.
https://docs.joomla.org/File_form_field_type