Hi,
Looks like file field is not being validated by Joomla! model class. I guess because files are not set in $_POST array, they are in $_FILES array. I think this is should be supported by Joomla because it supports the form field, so if there are people that agreed with me, I'll provide a PR in order to solve this.
To reproduce this issue, create a form with a file field marked as required. Then go to that form and try to save it attaching a file.
Getting a success message.
Error message saying that the file is not attached.
PHP 5.6.23
Joomla! 3.6.4 Stable [ Noether ] 21-October-2016 16:33 GMT
Nginx 1.10/Apache 2.4
Attaching a component to simplify testing for this issue
Labels |
Added:
?
|
@brianteeman it's not an issue on Component Creator (I'm the Lead developer of Component Creator) because we do not overload the validation method or the save method from Joomla!, so definitely it's a bug in Joomla! or at least, there are something missing the documentation alerting about that the field is not fully supported (actually Joomla! does not take care of moving the file, the developer has to do that)
@brianteeman It's works because is not being validated, but if you set as a required Joomla has to validate the field, so when it tries to do so, it cannot find the property in the POST data, so it throws an error.
As @vistiyos said, the issue is that $data var only stores the $_POST elements, not the $_FILES. I'm attaching a couple of screenshots. It's the save() method located in /libraries/legacy/controller/form.php
Here is the line, $_POST variables are assigned to $data
Here is the $_POST, $_FILES and $data variables after executing the line I referred in the previous screenshot. $_FILES[jform] are missing on $data. That causes the issue.
Category | ⇒ | Fields |
Status | New | ⇒ | Confirmed |
Any news about this issue??
Personally I'd say since you need specific processing for file upload fields anyway, you should also take care of the validation if needed. But that's really personal view.
I'm also not sure if there is an easy solution to this.
Yes, setting a file field to requires should not result in an error.
@Bakual There are two choices here:
Do not offer a file field is you are not fully supporting all the options you are offering
If you are already offering a file field, do whatever you need to do to support all the options you are offering.
I feel like the field is not completely and at least they need to add a disclaimer in the documentation warning about all the issues.
- Do not offer a file field is you are not fully supporting all the options you are offering
Removing the field is no option as it may be used by 3rd parties.
- If you are already offering a file field, do whatever you need to do to support all the options you are offering.
You can try, but I think that will be overly complex.
Option 3) Leave as it and make sure your code in the model takes care of that case. As I already explained you need special code anyway to process the uploaded file. The formfield doesn't do that for you, it just displays the formfield in the form with all the possible options (including "required" state).
Option 3) Leave as it and make sure your code in the model takes care of that case. As I already explained you need special code anyway to process the uploaded file. The formfield doesn't do that for you, it just displays the formfield in the form with all the possible options (including "required" state).
I understand that. However, it makes absolutely NO sense checking a field that is never loaded. I suggested, at least, to bypass that check.
You can try to do it. Personally I think it will result in a bad hack.
Status | Confirmed | ⇒ | Discussion |
You can actually get at it with JFormRule
https://docs.joomla.org/Server-side_form_validation
Something like this:
class JFormRuleUpload extends JFormRule
{
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null)
{
$name = (string)$element->attributes()->name;
if(@$_FILES['jform']['name'][$name])
return true;
return false;
}
}
Status | Discussion | ⇒ | Confirmed |
Setting back to confirmed as this is a confirmed issue no matter the difficulty of the solution.
The documentation clearly states
required Cannot be used with this field type. If the field is marked as required it will always fail validation regardless of whether a file has been uploaded or not. The suggested workaround is to add a filerequired attribute which can be tested in your own file handling code.
This should be closed as expected behaviour cc @zero-24
Status | Confirmed | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-08-23 19:32:17 |
Closed_By | ⇒ | zero-24 | |
Labels |
Added:
No Code Attached Yet
Removed: ? |
Agree closing
I can confirm your finding with this component from component-creator when the file field is a required field. However I am not sure if it is a Joomla bug or a bug with component creator
@aDaneInSpain can you take a look at this please