No Code Attached Yet J3 Issue
avatar vistiyos
vistiyos
8 Nov 2016

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.

Steps to reproduce the issue

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.

Expected result

Getting a success message.

Actual result

Error message saying that the file is not attached.

System information (as much as possible)

PHP 5.6.23
Joomla! 3.6.4 Stable [ Noether ] 21-October-2016 16:33 GMT
Nginx 1.10/Apache 2.4

Additional comments

Attaching a component to simplify testing for this issue

com_test-1.0.0.zip

avatar vistiyos vistiyos - open - 8 Nov 2016
avatar joomla-cms-bot joomla-cms-bot - change - 8 Nov 2016
Labels Added: ?
avatar brianteeman
brianteeman - comment - 8 Nov 2016

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

avatar vistiyos
vistiyos - comment - 9 Nov 2016

@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)

avatar brianteeman
brianteeman - comment - 9 Nov 2016

@vistiyos I didnt say it was i just wanted to confirm it 100% before continuing

What is interesting is that this works perfectly EXCEPT when it is a required field

avatar vistiyos
vistiyos - comment - 9 Nov 2016

@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.

avatar jsanchezgr
jsanchezgr - comment - 9 Nov 2016

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
selection_001

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.
selection_002

avatar brianteeman brianteeman - change - 9 Nov 2016
Category Fields
avatar brianteeman brianteeman - change - 9 Nov 2016
Status New Confirmed
avatar vistiyos
vistiyos - comment - 9 Jan 2017

Any news about this issue??

avatar Bakual
Bakual - comment - 9 Jan 2017

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.

avatar jsanchezgr
jsanchezgr - comment - 9 Jan 2017

@Bakual that's ok, but in that case, Joomla! should bypass the validation for those kind of fields. So, some action is required on this.

avatar aDaneInSpain
aDaneInSpain - comment - 9 May 2017

Yes, setting a file field to requires should not result in an error.

avatar vistiyos
vistiyos - comment - 9 May 2017

@Bakual There are two choices here:

  1. Do not offer a file field is you are not fully supporting all the options you are offering

  2. 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.

avatar Bakual
Bakual - comment - 9 May 2017
  1. 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.

  1. 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).

avatar jsanchezgr
jsanchezgr - comment - 9 May 2017

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.

avatar Bakual
Bakual - comment - 9 May 2017

You can try to do it. Personally I think it will result in a bad hack.

avatar franz-wohlkoenig franz-wohlkoenig - change - 8 Nov 2017
Status Confirmed Discussion
avatar brianteeman brianteeman - labeled - 25 Mar 2018
avatar AdamDocherty
AdamDocherty - comment - 11 Jul 2018

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;
    }
}
avatar jwaisner jwaisner - change - 18 Mar 2020
Status Discussion Confirmed
avatar jwaisner
jwaisner - comment - 18 Mar 2020

Setting back to confirmed as this is a confirmed issue no matter the difficulty of the solution.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12832.

avatar brianteeman
brianteeman - comment - 23 Aug 2022

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

avatar zero-24 zero-24 - change - 23 Aug 2022
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: ?
avatar zero-24 zero-24 - close - 23 Aug 2022
avatar zero-24
zero-24 - comment - 23 Aug 2022

Agree closing

Add a Comment

Login with GitHub to post a comment