Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion How to properly user JFormFieldFile???

Date: Sun, 25 Mar 2012 05:41:25 -0700 (PDT)
From: elin <elin.war...@gmail.com>
To: joomla-dev-cms@googlegroups.com
Message-ID: <12788280.83.1332679285691.JavaMail.geo-discussion-forums@vbat19>
In-Reply-To: <CABYB9+APvn3ujS+AZvnp04eVP5FCn2u2hONxXyk0rnq2KjkA+Q@mail.gmail.com>
References: <10052903.1387.1332517162010.JavaMail.geo-discussion-forums@vbut24>
 <20089811.1745.1332538024443.JavaMail.geo-discussion-forums@vbxq27>
 <28234284.147.1332589635515.JavaMail.geo-discussion-forums@yneo2> <14299204.354.1332615764190.JavaMail.geo-discussion-forums@vbhy1>
 <CABYB9+APvn3ujS+AZvnp04eVP5FCn2u2hONxXyk0rnq2KjkA+Q@mail.gmail.com>
Subject: Re: [jcms] Re: How to properly user JFormFieldFile???
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_81_6152849.1332679285687"

------=_Part_81_6152849.1332679285687
Content-Type: multipart/alternative; 
	boundary="----=_Part_82_29733976.1332679285687"

------=_Part_82_29733976.1332679285687
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable


Required is not working because it assumes that you are going to save=20
something from $data in a field.=20
https://github.com/joomla/joomla-platform/blob/staging/libraries/joomla/for=
m/form.php#L1847
So the issue I think is in how required is attempting to validate in this=
=20
case.  It needs to check  $_FILES not $data.

If the field is  not going to save something in a manner typical of other=
=20
fields the required is going to fail unless it is overriding that.  =20
https://github.com/joomla/joomla-platform/blob/staging/libraries/joomla/for=
m/fields/file.php#L54

So ... possibly the field needs to handle validation for required itself.=
=20
Or you could make a custom rule that handles file validation including=20
dealing correctly with required.

=20
Elin=20

On Saturday, Marc)odel when you save
>
> to shift the file on disk somewhere.htCheers,
>
> Sam Moffatt
> http://pasamio.id.au
>
> On Sun, Mar 25, 2012 at 5:02 AM, elin <elin.war...@gmail.com> wrote:
> > I have to say that field has always been a mystery to me. It has never=
=20
> saved
> > and I guess you have figured out why but  it's not clear what it should=
=20
> even
> > save. I think of it more like the field in the installer that you use t=
o
> > find the zip file but you don't ever actually store that information.
> >  Usually the fields  like the media or imagelist or filelist fields wou=
ld
> > just save the reference to the name and location of the file.
> >
> > I have always thought that what you should do is extend it to make a=20
> custom
> > field that is actually useful for the file types you want.
> >
> > Elin
> >
> >
> >> Thanks for the reply Elin. Of course I can share a little bit of code:
> >>
> >> so here is the form:
> >>
> >> <?xml version=3D"1.0" encoding=3D"utf-8"?>
> >> <form>
> >>     <fieldset>
> >>         <field name=3D"hotspots_kml_id" type=3D"text" default=3D"0"
> >> label=3D"JGLOBAL_FIELD_ID_LABEL"
> >>             readonly=3D"true" class=3D"readonly"
> >>             description=3D"JGLOBAL_FIELD_ID_=E2=80=8BDESC"/>
> >>
> >>
> >>         ....
> >>
> >>
> >>         <field name=3D"kml_file" type=3D"file" label=3D"COM_HOTSPOTS_K=
ML_FILE"
> >>                description=3D"COM_HOTSPOTS_KML_=E2=80=8BFILE_DESC"=20
> required=3D"true"/>
> >>
> >>
> >>         ....
> >>
> >>
> >>     </fieldset>
> >>
> >> </form>
> >>
> >> my edit.php layout file:
> >>
> >> <form enctype=3D"multipart/form-data" action=3D"<?php echo
> >> JRoute::_('index.php?option=3D=E2=80=8Bcom_hotspots&view=3Dkml&=E2=80=
=8Bhotspots_kml_id=3D' .
> >> (int)$this->item->hotspots_=E2=80=8Bkml_id); ?>" method=3D"post" class=
=3D"form"
> >> name=3D"adminForm" id=3D"adminForm" >
> >>
> >>     <div class=3D"width-60 fltlft">
> >>         <fieldset class=3D"adminform">
> >>             <legend><?php echo empty($this->item->hotspots_=E2=80=8Bkm=
l_id) ?
> >> JText::_('COM_HOTSPOTS_NEW_=E2=80=8BKML') :=20
> JText::sprintf('COM_HOTSPOTS_=E2=80=8BEDIT_KML',
> >> $this->item->hotspots_kml_id); ?></legend>
> >>
> >>             <ul class=3D"adminformlist">
> >>                 ....
> >>                 <li>
> >>                     <?php echo=20
> $this->form->getLabel('=E2=80=8Bhotspots_kml_id');
> >> ?>
> >>                     <?php echo=20
> $this->form->getInput('=E2=80=8Bhotspots_kml_id');
> >> ?>
> >>                 </li>
> >>         ....
> >>
> >>                 <li>
> >>                     <?php echo $this->form->getLabel('kml_=E2=80=8Bfil=
e'); ?>
> >>                     <?php echo $this->form->getInput('kml_=E2=80=8Bfil=
e'); ?>
> >>
> >>                 </li>
> >>             </ul>
> >>
> >>             .....
> >>
> >>     <input type=3D"hidden" name=3D"task" value=3D""/>
> >>     <?php echo JHTML::_('form.token'); ?>
> >> </form>
> >>
> >> So when you  click on save, we go in the kml controller that extends
> >> JControllerForm:
> >> class HotspotsControllerKml extends JControllerForm {
> >> ....
> >> }
> >>
> >> If I don't override the save function, then we use the parent function
> >> which looks like this:
> >>
> >> public function save($key =3D null, $urlVar =3D null)
> >>     {
> >>
> >>         // Check for request forgeries.
> >>         JRequest::checkToken() or jexit(JText::_('JINVALID_=E2=80=8BTO=
KEN'));
> >>
> >>
> >>         // Initialise variables.
> >>         $app =3D JFactory::getApplication();
> >>         $lang =3D JFactory::getLanguage();
> >>         $model =3D $this->getModel();
> >>         $table =3D $model->getTable();
> >>         $data =3D JRequest::getVar('jform', array(), 'post', 'array');
> >>         $checkin =3D property_exists($table, 'checked_out');
> >>         $context =3D "$this->option.edit.$this->=E2=80=8Bcontext";
> >>         $task =3D $this->getTask();
> >>
> >> .....
> >>
> >>
> >>
> >> // Validate the posted data.
> >>         // Sometimes the form needs some posted data, such as for=20
> plugins
> >> and modules.
> >>         $form =3D $model->getForm($data, false);
> >>
> >>         if (!$form)
> >>         {
> >>             $app->enqueueMessage($model->=E2=80=8BgetError(), 'error')=
;
> >>
> >>             return false;
> >>         }
> >>
> >>         // Test whether the data is valid.
> >>         $validData =3D $model->validate($form, $data);
> >>
> >> .....
> >>
> >>         if ($validData =3D=3D=3D false)
> >>         {
> >> ....
> >>
> >> }
> >>
> >> As you can see in this function we do:
> >> $data =3D JRequest::getVar('jform', array(), 'post', 'array');
> >>
> >> and this is all ok, but the file is not sent in the post array, but it=
=20
> is
> >> in the $_FILES array.
> >>
> >> And because of this the validation in the model fails.
> >>
> >> So as I said, I overwrote the save function and added a=20
> $data['kml_file']
> >> =3D true; if the user has submitted a file.
> >>
> >> The question is - should I overwrite this function? Or should I do the
> >> checks in the validate function?
> >>
> >> Since the validate function expects to receive the $form and the $data=
 I
> >> think that we should not do any interactions with the $_POST and $_FIL=
ES
> >> arrays there, right?
> >>
> >> Am I doing something wrong here? Is there a better approach to this???
> >>
> >> Thanks in advance!
> >> Daniel
> >>
> >> On Friday, March 23, 2012 10:27:04 PM UTC+1, elin wrote:
> >>>
> >>> I'm not sure I understand what is happening. Maybe you could show us=
=20
> your
> >>> code or xml?
> >>>
> >>>
> >>> Are you saying that the field has been filled out but the validation =
is
> >>> saying it is empty?
> >>>
> >>>
> >>> Elin
> >>>
> >>>
> >>> On Friday, March 23, 2012 11:39:22 AM UTC-4, Daniel D. / compojoom=20
> wrote:
> >>>>
> >>>> Hey Guys,
> >>>> For the last hour I've been trying to figure out how to use a
> >>>> JFormFieldFile field that is set to required.
> >>>>
> >>>> The thing is when I save the form data, the save function complains=
=20
> that
> >>>> the file field is empty and because it is required -> the validation
> >>>> function returns false...
> >>>>
> >>>> I went around this by overriding the whole save function in the
> >>>> JControllerForm. (I just checked if the  $_Files array contains the=
=20
> file and
> >>>> added it to the $data array.) But this approach feels really stupid=
=20
> for
> >>>> me??? I basically have the same save function + 3 lines that handle=
=20
> the file
> >>>> field.
> >>>>
> >>>> Is there any other way to let JForm know that we have a field that i=
s
> >>>> not in the post array? Preprocess form in the controller or somethin=
g?
> >>>>
> >>>> Regards,
> >>>> Daniel
> >
> > --
> > You received this message because you are subscribed to the Google Grou=
ps
> > "Joomla! CMS Development" group.
> > To view this discussion on the web, visit
> > https://groups.google.com/d/=E2=80=8Bmsg/joomla-dev-cms/-/=E2=80=8BNc8I=
pWwUHz8J<https://groups.google.com/d/msg/joomla-dev-cms/-/Nc8IpWwUHz8J>
> .
> >
> > To post to this group, send an email to joomla-dev-cms@googlegroups.=E2=
=80=8Bcom<joomla-dev-cms@googlegroups.com>
> .
> > To unsubscribe from this group, send email to
> > joomla-dev-cms+unsubscribe@=E2=80=8Bgooglegroups.com<joomla-dev-cms%2Bu=
nsubscribe@googlegroups.com>
> .
> > For more options, visit this group at
> > http://groups.google.com/=E2=80=8Bgroup/joomla-dev-cms?hl=3Den-GB<http:=
//groups.google.com/group/joomla-dev-cms?hl=3Den-GB>
> .
>
>
On Saturday, March 24, 2012 10:30:58 PM UTC-4, Samuel Moffatt wrote:
>
> You have to write something in your model to process and save it. This
> is primarily a PHP side effect that it'll be jammed into $_FILES and
> you have to use move_uploaded_file (or JFile::upload) to shift it
> somewhere on disk where you want to use it.
>
> No idea why the required thing isn't working, possibly a bug but you
> shouldn't need to subclass, just pick it up in the model when you save
> to shift the file on disk somewhere.
>
> Cheers,
>
> Sam Moffatt
> http://pasamio.id.au
>
> On Sun, Mar 25, 2012 at 5:02 AM, elin <elin.war...@gmail.com> wrote:
> > I have to say that field has always been a mystery to me. It has never=
=20
> saved
> > and I guess you have figured out why but  it's not clear what it should=
=20
> even
> > save. I think of it more like the field in the installer that you use t=
o
> > find the zip file but you don't ever actually store that information.
> >  Usually the fields  like the media or imagelist or filelist fields wou=
ld
> > just save the reference to the name and location of the file.
> >
> > I have always thought that what you should do is extend it to make a=20
> custom
> > field that is actually useful for the file types you want.
> >
> > Elin
> >
> >
> >> Thanks for the reply Elin. Of course I can share a little bit of code:
> >>
> >> so here is the form:
> >>
> >> <?xml version=3D"1.0" encoding=3D"utf-8"?>
> >> <form>
> >>     <fieldset>
> >>         <field name=3D"hotspots_kml_id" type=3D"text" default=3D"0"
> >> label=3D"JGLOBAL_FIELD_ID_LABEL"
> >>             readonly=3D"true" class=3D"readonly"
> >>             description=3D"JGLOBAL_FIELD_ID_=E2=80=8BDESC"/>
> >>
> >>
> >>         ....
> >>
> >>
> >>         <field name=3D"kml_file" type=3D"file" label=3D"COM_HOTSPOTS_K=
ML_FILE"
> >>                description=3D"COM_HOTSPOTS_KML_=E2=80=8BFILE_DESC"=20
> required=3D"true"/>
> >>
> >>
> >>         ....
> >>
> >>
> >>     </fieldset>
> >>
> >> </form>
> >>
> >> my edit.php layout file:
> >>
> >> <form enctype=3D"multipart/form-data" action=3D"<?php echo
> >> JRoute::_('index.php?option=3D=E2=80=8Bcom_hotspots&view=3Dkml&=E2=80=
=8Bhotspots_kml_id=3D' .
> >> (int)$this->item->hotspots_=E2=80=8Bkml_id); ?>" method=3D"post" class=
=3D"form"
> >> name=3D"adminForm" id=3D"adminForm" >
> >>
> >>     <div class=3D"width-60 fltlft">
> >>         <fieldset class=3D"adminform">
> >>             <legend><?php echo empty($this->item->hotspots_=E2=80=8Bkm=
l_id) ?
> >> JText::_('COM_HOTSPOTS_NEW_=E2=80=8BKML') :=20
> JText::sprintf('COM_HOTSPOTS_=E2=80=8BEDIT_KML',
> >> $this->item->hotspots_kml_id); ?></legend>
> >>
> >>             <ul class=3D"adminformlist">
> >>                 ....
> >>                 <li>
> >>                     <?php echo=20
> $this->form->getLabel('=E2=80=8Bhotspots_kml_id');
> >> ?>
> >>                     <?php echo=20
> $this->form->getInput('=E2=80=8Bhotspots_kml_id');
> >> ?>
> >>                 </li>
> >>         ....
> >>
> >>                 <li>
> >>                     <?php echo $this->form->getLabel('kml_=E2=80=8Bfil=
e'); ?>
> >>                     <?php echo $this->form->getInput('kml_=E2=80=8Bfil=
e'); ?>
> >>
> >>                 </li>
> >>             </ul>
> >>
> >>             .....
> >>
> >>     <input type=3D"hidden" name=3D"task" value=3D""/>
> >>     <?php echo JHTML::_('form.token'); ?>
> >> </form>
> >>
> >> So when you  click on save, we go in the kml controller that extends
> >> JControllerForm:
> >> class HotspotsControllerKml extends JControllerForm {
> >> ....
> >> }
> >>
> >> If I don't override the save function, then we use the parent function
> >> which looks like this:
> >>
> >> public function save($key =3D null, $urlVar =3D null)
> >>     {
> >>
> >>         // Check for request forgeries.
> >>         JRequest::checkToken() or jexit(JText::_('JINVALID_=E2=80=8BTO=
KEN'));
> >>
> >>
> >>         // Initialise variables.
> >>         $app =3D JFactory::getApplication();
> >>         $lang =3D JFactory::getLanguage();
> >>         $model =3D $this->getModel();
> >>         $table =3D $model->getTable();
> >>         $data =3D JRequest::getVar('jform', array(), 'post', 'array');
> >>         $checkin =3D property_exists($table, 'checked_out');
> >>         $context =3D "$this->option.edit.$this->=E2=80=8Bcontext";
> >>         $task =3D $this->getTask();
> >>
> >> .....
> >>
> >>
> >>
> >> // Validate the posted data.
> >>         // Sometimes the form needs some posted data, such as for=20
> plugins
> >> and modules.
> >>         $form =3D $model->getForm($data, false);
> >>
> >>         if (!$form)
> >>         {
> >>             $app->enqueueMessage($model->=E2=80=8BgetError(), 'error')=
;
> >>
> >>             return false;
> >>         }
> >>
> >>         // Test whether the data is valid.
> >>         $validData =3D $model->validate($form, $data);
> >>
> >> .....
> >>
> >>         if ($validData =3D=3D=3D false)
> >>         {
> >> ....
> >>
> >> }
> >>
> >> As you can see in this function we do:
> >> $data =3D JRequest::getVar('jform', array(), 'post', 'array');
> >>
> >> and this is all ok, but the file is not sent in the post array, but it=
=20
> is
> >> in the $_FILES array.
> >>
> >> And because of this the validation in the model fails.
> >>
> >> So as I said, I overwrote the save function and added a=20
> $data['kml_file']
> >> =3D true; if the user has submitted a file.
> >>
> >> The question is - should I overwrite this function? Or should I do the
> >> checks in the validate function?
> >>
> >> Since the validate function expects to receive the $form and the $data=
 I
> >> think that we should not do any interactions with the $_POST and $_FIL=
ES
> >> arrays there, right?
> >>
> >> Am I doing something wrong here? Is there a better approach to this???
> >>
> >> Thanks in advance!
> >> Daniel
> >>
> >> On Friday, March 23, 2012 10:27:04 PM UTC+1, elin wrote:
> >>>
> >>> I'm not sure I understand what is happening. Maybe you could show us=
=20
> your
> >>> code or xml?
> >>>
> >>>
> >>> Are you saying that the field has been filled out but the validation =
is
> >>> saying it is empty?
> >>>
> >>>
> >>> Elin
> >>>
> >>>
> >>> On Friday, March 23, 2012 11:39:22 AM UTC-4, Daniel D. / compojoom=20
> wrote:
> >>>>
> >>>> Hey Guys,
> >>>> For the last hour I've been trying to figure out how to use a
> >>>> JFormFieldFile field that is set to required.
> >>>>
> >>>> The thing is when I save the form data, the save function complains=
=20
> that
> >>>> the file field is empty and because it is required -> the validation
> >>>> function returns false...
> >>>>
> >>>> I went around this by overriding the whole save function in the
> >>>> JControllerForm. (I just checked if the  $_Files array contains the=
=20
> file and
> >>>> added it to the $data array.) But this approach feels really stupid=
=20
> for
> >>>> me??? I basically have the same save function + 3 lines that handle=
=20
> the file
> >>>> field.
> >>>>
> >>>> Is there any other way to let JForm know that we have a field that i=
s
> >>>> not in the post array? Preprocess form in the controller or somethin=
g?
> >>>>
> >>>> Regards,
> >>>> Daniel
> >
> > --
> > You received this message because you are subscribed to the Google Grou=
ps
> > "Joomla! CMS Development" group.
> > To view this discussion on the web, visit
> > https://groups.google.com/d/=E2=80=8Bmsg/joomla-dev-cms/-/=E2=80=8BNc8I=
pWwUHz8J<https://groups.google.com/d/msg/joomla-dev-cms/-/Nc8IpWwUHz8J>
> .
> >
> > To post to this group, send an email to joomla-dev-cms@googlegroups.=E2=
=80=8Bcom<joomla-dev-cms@googlegroups.com>
> .
> > To unsubscribe from this group, send email to
> > joomla-dev-cms+unsubscribe@=E2=80=8Bgooglegroups.com<joomla-dev-cms%2Bu=
nsubscribe@googlegroups.com>
> .
> > For more options, visit this group at
> > http://groups.google.com/=E2=80=8Bgroup/joomla-dev-cms?hl=3Den-GB<http:=
//groups.google.com/group/joomla-dev-cms?hl=3Den-GB>
> .
>
>
------=_Part_82_29733976.1332679285687
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<br><div>Required is not working because it assumes that you are going to s=
ave something from $data in a field.&nbsp;</div><div><a href=3D"https://git=
hub.com/joomla/joomla-platform/blob/staging/libraries/joomla/form/form.php#=
L1847">https://github.com/joomla/joomla-platform/blob/staging/libraries/joo=
mla/form/form.php#L1847</a></div><div>So the issue I think is in how requir=
ed is attempting to validate in this case. &nbsp;It needs to check &nbsp;$_=
FILES not $data.</div><div><br></div><div>If the field is &nbsp;not going t=
o save something in a manner typical of other fields the required is going =
to fail unless it is overriding that. &nbsp;&nbsp;</div><div><a href=3D"htt=
ps://github.com/joomla/joomla-platform/blob/staging/libraries/joomla/form/f=
ields/file.php#L54">https://github.com/joomla/joomla-platform/blob/staging/=
libraries/joomla/form/fields/file.php#L54</a><br></div><div><br></div><div>=
So ... possibly the field needs to handle validation for required itself. O=
r you could make a custom rule that handles file validation including deali=
ng correctly with required.</div><div><br></div><div>&nbsp;</div><div>Elin&=
nbsp;<br><br>On Saturday, Marc)odel when you save<blockquote class=3D"gmail=
_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;p=
adding-left: 1ex;"><p>to shift the file on disk somewhere.htCheers,</p><p>S=
am Moffatt<br><a href=3D"http://pasamio.id.au" target=3D"_blank">http://pas=
amio.id.au</a></p><p></p><p>On Sun, Mar 25, 2012 at 5:02 AM, elin &lt;<a hr=
ef=3D"mailto:elin.war...@gmail.com" target=3D"_blank">elin.war...@gmail.com=
</a>&gt; wrote:<br>&gt; I have to say that field has always been a mystery =
to me. It has never saved<br>&gt; and I guess you have figured out why but =
&nbsp;it's not clear what it should even<br>&gt; save. I think of it more l=
ike the field in the installer that you use to<br>&gt; find the zip file bu=
t you don't ever actually store that information.<br>&gt; &nbsp;Usually the=
 fields &nbsp;like the media or imagelist or filelist fields would<br>&gt; =
just save the reference to the name and location of the file.<br>&gt;<br>&g=
t; I have always thought that what you should do is extend it to make a cus=
tom<br>&gt; field that is actually useful for the file types you want.<br>&=
gt;<br>&gt; Elin<br>&gt;<br>&gt;<br>&gt;&gt; Thanks for the reply Elin. Of =
course I can share a little bit of code:<br>&gt;&gt;<br>&gt;&gt; so here is=
 the form:<br>&gt;&gt;<br>&gt;&gt; &lt;?xml version=3D"1.0" encoding=3D"utf=
-8"?&gt;<br>&gt;&gt; &lt;form&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &lt;fields=
et&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;field name=3D"=
hotspots_kml_id" type=3D"text" default=3D"0"<br>&gt;&gt; label=3D"JGLOBAL_F=
IELD_ID_LABEL"<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbs=
p;&nbsp; readonly=3D"true" class=3D"readonly"<br>&gt;&gt; &nbsp;&nbsp;&nbsp=
; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; description=3D"JGLOBAL_FIELD_ID_=E2=
=80=8BDESC"/&gt;<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; ....<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name=3D"kml_file" type=3D"file" lab=
el=3D"COM_HOTSPOTS_KML_FILE"<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; description=3D"COM_HOTSP=
OTS_KML_=E2=80=8BFILE_DESC" required=3D"true"/&gt;<br>&gt;&gt;<br>&gt;&gt;<=
br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ....<br>&gt;&gt;<br>=
&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &lt;/fieldset&gt;<br>&gt;&gt;<br>&g=
t;&gt; &lt;/form&gt;<br>&gt;&gt;<br>&gt;&gt; my edit.php layout file:<br>&g=
t;&gt;<br>&gt;&gt; &lt;form enctype=3D"multipart/form-data" action=3D"&lt;?=
php echo<br>&gt;&gt; JRoute::_('index.php?option=3D=E2=80=8Bcom_hotspots&am=
p;view=3Dkml&amp;=E2=80=8Bhotspots_kml_id=3D' .<br>&gt;&gt; (int)$this-&gt;=
item-&gt;hotspots_=E2=80=8Bkml_id); ?&gt;" method=3D"post" class=3D"form"<b=
r>&gt;&gt; name=3D"adminForm" id=3D"adminForm" &gt;<br>&gt;&gt;<br>&gt;&gt;=
 &nbsp;&nbsp;&nbsp; &lt;div class=3D"width-60 fltlft"&gt;<br>&gt;&gt; &nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;fieldset class=3D"adminform"&gt;<=
br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; &lt;legend&gt;&lt;?php echo empty($this-&gt;item-&gt;hotspots_=E2=80=8B=
kml_id) ?<br>&gt;&gt; JText::_('COM_HOTSPOTS_NEW_=E2=80=8BKML') : JText::sp=
rintf('COM_HOTSPOTS_=E2=80=8BEDIT_KML',<br>&gt;&gt; $this-&gt;item-&gt;hots=
pots_kml_id); ?&gt;&lt;/legend&gt;<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ul class=3D"adminfor=
mlist"&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ....<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt=
;li&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;?php echo $=
this-&gt;form-&gt;getLabel('=E2=80=8Bhotspots_kml_id');<br>&gt;&gt; ?&gt;<b=
r>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;?php echo $this-&gt;=
form-&gt;getInput('=E2=80=8Bhotspots_kml_id');<br>&gt;&gt; ?&gt;<br>&gt;&gt=
; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp; &lt;/li&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&n=
bsp; ....<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;li&gt;<br>&gt;&gt; &n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;?php echo $this-&gt;form-&gt;getL=
abel('kml_=E2=80=8Bfile'); ?&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp; &lt;?php echo $this-&gt;form-&gt;getInput('kml_=E2=80=8Bfile'); ?=
&gt;<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/li&gt;<br>&gt;&gt; &nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/ul&gt;<br=
>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp; .....<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &lt;input ty=
pe=3D"hidden" name=3D"task" value=3D""/&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; =
&lt;?php echo JHTML::_('form.token'); ?&gt;<br>&gt;&gt; &lt;/form&gt;<br>&g=
t;&gt;<br>&gt;&gt; So when you&nbsp; click on save, we go in the kml contro=
ller that extends<br>&gt;&gt; JControllerForm:<br>&gt;&gt; class HotspotsCo=
ntrollerKml extends JControllerForm {<br>&gt;&gt; ....<br>&gt;&gt; }<br>&gt=
;&gt;<br>&gt;&gt; If I don't override the save function, then we use the pa=
rent function<br>&gt;&gt; which looks like this:<br>&gt;&gt;<br>&gt;&gt; pu=
blic function save($key =3D null, $urlVar =3D null)<br>&gt;&gt; &nbsp;&nbsp=
;&nbsp; {<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // =
Check for request forgeries.<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nb=
sp; JRequest::checkToken() or jexit(JText::_('JINVALID_=E2=80=8BTOKEN'));<b=
r>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //=
 Initialise variables.<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $a=
pp =3D JFactory::getApplication();<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nb=
sp;&nbsp; $lang =3D JFactory::getLanguage();<br>&gt;&gt; &nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp;&nbsp; $model =3D $this-&gt;getModel();<br>&gt;&gt; &nbsp;&nbs=
p;&nbsp; &nbsp;&nbsp;&nbsp; $table =3D $model-&gt;getTable();<br>&gt;&gt; &=
nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $data =3D JRequest::getVar('jform', ar=
ray(), 'post', 'array');<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
$checkin =3D property_exists($table, 'checked_out');<br>&gt;&gt; &nbsp;&nbs=
p;&nbsp; &nbsp;&nbsp;&nbsp; $context =3D "$this-&gt;option.edit.$this-&gt;=
=E2=80=8Bcontext";<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $task =
=3D $this-&gt;getTask();<br>&gt;&gt;<br>&gt;&gt; .....<br>&gt;&gt;<br>&gt;&=
gt;<br>&gt;&gt;<br>&gt;&gt; // Validate the posted data.<br>&gt;&gt; &nbsp;=
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Sometimes the form needs some posted dat=
a, such as for plugins<br>&gt;&gt; and modules.<br>&gt;&gt; &nbsp;&nbsp;&nb=
sp; &nbsp;&nbsp;&nbsp; $form =3D $model-&gt;getForm($data, false);<br>&gt;&=
gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (!$form)<br>&gt;&g=
t; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &=
nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $app-&gt;enqueueMessage($model-&gt;=E2=
=80=8BgetError(), 'error');<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbs=
p;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return false;<br>&gt;&gt; &nbsp;&nbsp;&nb=
sp; &nbsp;&nbsp;&nbsp; }<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&=
nbsp;&nbsp; // Test whether the data is valid.<br>&gt;&gt; &nbsp;&nbsp;&nbs=
p; &nbsp;&nbsp;&nbsp; $validData =3D $model-&gt;validate($form, $data);<br>=
&gt;&gt;<br>&gt;&gt; .....<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp=
;&nbsp;&nbsp; if ($validData =3D=3D=3D false)<br>&gt;&gt; &nbsp;&nbsp;&nbsp=
; &nbsp;&nbsp;&nbsp; {<br>&gt;&gt; ....<br>&gt;&gt;<br>&gt;&gt; }<br>&gt;&g=
t;<br>&gt;&gt; As you can see in this function we do:<br>&gt;&gt; $data =3D=
 JRequest::getVar('jform', array(), 'post', 'array');<br>&gt;&gt;<br>&gt;&g=
t; and this is all ok, but the file is not sent in the post array, but it i=
s<br>&gt;&gt; in the $_FILES array.<br>&gt;&gt;<br>&gt;&gt; And because of =
this the validation in the model fails.<br>&gt;&gt;<br>&gt;&gt; So as I sai=
d, I overwrote the save function and added a $data['kml_file']<br>&gt;&gt; =
=3D true; if the user has submitted a file.<br>&gt;&gt;<br>&gt;&gt; The que=
stion is - should I overwrite this function? Or should I do the<br>&gt;&gt;=
 checks in the validate function?<br>&gt;&gt;<br>&gt;&gt; Since the validat=
e function expects to receive the $form and the $data I<br>&gt;&gt; think t=
hat we should not do any interactions with the $_POST and $_FILES<br>&gt;&g=
t; arrays there, right?<br>&gt;&gt;<br>&gt;&gt; Am I doing something wrong =
here? Is there a better approach to this???<br>&gt;&gt;<br>&gt;&gt; Thanks =
in advance!<br>&gt;&gt; Daniel<br>&gt;&gt;<br>&gt;&gt; On Friday, March 23,=
 2012 10:27:04 PM UTC+1, elin wrote:<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; I'm no=
t sure I understand what is happening. Maybe you could show us your<br>&gt;=
&gt;&gt; code or xml?<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; Are y=
ou saying that the field has been filled out but the validation is<br>&gt;&=
gt;&gt; saying it is empty?<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;=
 Elin<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;&gt; On Friday, March 23, =
2012 11:39:22 AM UTC-4, Daniel D. / compojoom wrote:<br>&gt;&gt;&gt;&gt;<br=
>&gt;&gt;&gt;&gt; Hey Guys,<br>&gt;&gt;&gt;&gt; For the last hour I've been=
 trying to figure out how to use a<br>&gt;&gt;&gt;&gt; JFormFieldFile field=
 that is set to required.<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; The thing=
 is when I save the form data, the save function complains that<br>&gt;&gt;=
&gt;&gt; the file field is empty and because it is required -&gt; the valid=
ation<br>&gt;&gt;&gt;&gt; function returns false...<br>&gt;&gt;&gt;&gt;<br>=
&gt;&gt;&gt;&gt; I went around this by overriding the whole save function i=
n the<br>&gt;&gt;&gt;&gt; JControllerForm. (I just checked if the&nbsp; $_F=
iles array contains the file and<br>&gt;&gt;&gt;&gt; added it to the $data =
array.) But this approach feels really stupid for<br>&gt;&gt;&gt;&gt; me???=
 I basically have the same save function + 3 lines that handle the file<br>=
&gt;&gt;&gt;&gt; field.<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Is there an=
y other way to let JForm know that we have a field that is<br>&gt;&gt;&gt;&=
gt; not in the post array? Preprocess form in the controller or something?<=
br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Regards,<br>&gt;&gt;&gt;&gt; Daniel=
<br>&gt;<br>&gt; --<br>&gt; You received this message because you are subsc=
ribed to the Google Groups<br>&gt; "Joomla! CMS Development" group.<br>&gt;=
 To view this discussion on the web, visit<br>&gt; <a href=3D"https://group=
s.google.com/d/msg/joomla-dev-cms/-/Nc8IpWwUHz8J" target=3D"_blank">https:/=
/groups.google.com/d/=E2=80=8Bmsg/joomla-dev-cms/-/=E2=80=8BNc8IpWwUHz8J</a=
>.<br>&gt;<br>&gt; To post to this group, send an email to <a href=3D"mailt=
o:joomla-dev-cms@googlegroups.com" target=3D"_blank">joomla-dev-cms@googleg=
roups.=E2=80=8Bcom</a>.<br>&gt; To unsubscribe from this group, send email =
to<br>&gt; <a href=3D"mailto:joomla-dev-cms%2Bunsubscribe@googlegroups.com"=
 target=3D"_blank">joomla-dev-cms+unsubscribe@=E2=80=8Bgooglegroups.com</a>=
.<br>&gt; For more options, visit this group at<br>&gt; <a href=3D"http://g=
roups.google.com/group/joomla-dev-cms?hl=3Den-GB" target=3D"_blank">http://=
groups.google.com/=E2=80=8Bgroup/joomla-dev-cms?hl=3Den-GB</a>.<br></p><p><=
/p><p></p><p></p><p></p></blockquote></div><br>On Saturday, March 24, 2012 =
10:30:58 PM UTC-4, Samuel Moffatt wrote:<blockquote class=3D"gmail_quote" s=
tyle=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-le=
ft: 1ex;">You have to write something in your model to process and save it.=
 This<br>is primarily a PHP side effect that it'll be jammed into $_FILES a=
nd<br>you have to use move_uploaded_file (or JFile::upload) to shift it<br>=
somewhere on disk where you want to use it.<p>No idea why the required thin=
g isn't working, possibly a bug but you<br>shouldn't need to subclass, just=
 pick it up in the model when you save<br>to shift the file on disk somewhe=
re.</p><p>Cheers,</p><p>Sam Moffatt<br><a href=3D"http://pasamio.id.au" tar=
get=3D"_blank">http://pasamio.id.au</a></p><p></p><p>On Sun, Mar 25, 2012 a=
t 5:02 AM, elin &lt;<a href=3D"mailto:elin.war...@gmail.com" target=3D"_bla=
nk">elin.war...@gmail.com</a>&gt; wrote:<br>&gt; I have to say that field h=
as always been a mystery to me. It has never saved<br>&gt; and I guess you =
have figured out why but &nbsp;it's not clear what it should even<br>&gt; s=
ave. I think of it more like the field in the installer that you use to<br>=
&gt; find the zip file but you don't ever actually store that information.<=
br>&gt; &nbsp;Usually the fields &nbsp;like the media or imagelist or filel=
ist fields would<br>&gt; just save the reference to the name and location o=
f the file.<br>&gt;<br>&gt; I have always thought that what you should do i=
s extend it to make a custom<br>&gt; field that is actually useful for the =
file types you want.<br>&gt;<br>&gt; Elin<br>&gt;<br>&gt;<br>&gt;&gt; Thank=
s for the reply Elin. Of course I can share a little bit of code:<br>&gt;&g=
t;<br>&gt;&gt; so here is the form:<br>&gt;&gt;<br>&gt;&gt; &lt;?xml versio=
n=3D"1.0" encoding=3D"utf-8"?&gt;<br>&gt;&gt; &lt;form&gt;<br>&gt;&gt; &nbs=
p;&nbsp;&nbsp; &lt;fieldset&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=
&nbsp; &lt;field name=3D"hotspots_kml_id" type=3D"text" default=3D"0"<br>&g=
t;&gt; label=3D"JGLOBAL_FIELD_ID_LABEL"<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbs=
p;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; readonly=3D"true" class=3D"readonly"<br>&=
gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; descriptio=
n=3D"JGLOBAL_FIELD_ID_=E2=80=8BDESC"/&gt;<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&g=
t; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ....<br>&gt;&gt;<br>&gt;&gt;<=
br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name=3D"km=
l_file" type=3D"file" label=3D"COM_HOTSPOTS_KML_FILE"<br>&gt;&gt; &nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
 description=3D"COM_HOTSPOTS_KML_=E2=80=8BFILE_DESC" required=3D"true"/&gt;=
<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp; ....<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &lt;/field=
set&gt;<br>&gt;&gt;<br>&gt;&gt; &lt;/form&gt;<br>&gt;&gt;<br>&gt;&gt; my ed=
it.php layout file:<br>&gt;&gt;<br>&gt;&gt; &lt;form enctype=3D"multipart/f=
orm-data" action=3D"&lt;?php echo<br>&gt;&gt; JRoute::_('index.php?option=
=3D=E2=80=8Bcom_hotspots&amp;view=3Dkml&amp;=E2=80=8Bhotspots_kml_id=3D' .<=
br>&gt;&gt; (int)$this-&gt;item-&gt;hotspots_=E2=80=8Bkml_id); ?&gt;" metho=
d=3D"post" class=3D"form"<br>&gt;&gt; name=3D"adminForm" id=3D"adminForm" &=
gt;<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &lt;div class=3D"width-60 fl=
tlft"&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;fields=
et class=3D"adminform"&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;legend&gt;&lt;?php echo empty($this-&gt;=
item-&gt;hotspots_=E2=80=8Bkml_id) ?<br>&gt;&gt; JText::_('COM_HOTSPOTS_NEW=
_=E2=80=8BKML') : JText::sprintf('COM_HOTSPOTS_=E2=80=8BEDIT_KML',<br>&gt;&=
gt; $this-&gt;item-&gt;hotspots_kml_id); ?&gt;&lt;/legend&gt;<br>&gt;&gt;<b=
r>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; &lt;ul class=3D"adminformlist"&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ....<br>&=
gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp; &lt;li&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp; &lt;?php echo $this-&gt;form-&gt;getLabel('=E2=80=8Bhotspots_km=
l_id');<br>&gt;&gt; ?&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; &lt;?php echo $this-&gt;form-&gt;getInput('=E2=80=8Bhotspots_kml_id');<b=
r>&gt;&gt; ?&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/li&gt;<br>&gt;&gt; &nbsp;=
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ....<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
; &lt;li&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;?php e=
cho $this-&gt;form-&gt;getLabel('kml_=E2=80=8Bfile'); ?&gt;<br>&gt;&gt; &nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;?php echo $this-&gt;form-&gt;getIn=
put('kml_=E2=80=8Bfile'); ?&gt;<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt=
;/li&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp; &lt;/ul&gt;<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .....<br>&gt;&gt;<br>&gt;&gt; &nbs=
p;&nbsp;&nbsp; &lt;input type=3D"hidden" name=3D"task" value=3D""/&gt;<br>&=
gt;&gt; &nbsp;&nbsp;&nbsp; &lt;?php echo JHTML::_('form.token'); ?&gt;<br>&=
gt;&gt; &lt;/form&gt;<br>&gt;&gt;<br>&gt;&gt; So when you&nbsp; click on sa=
ve, we go in the kml controller that extends<br>&gt;&gt; JControllerForm:<b=
r>&gt;&gt; class HotspotsControllerKml extends JControllerForm {<br>&gt;&gt=
; ....<br>&gt;&gt; }<br>&gt;&gt;<br>&gt;&gt; If I don't override the save f=
unction, then we use the parent function<br>&gt;&gt; which looks like this:=
<br>&gt;&gt;<br>&gt;&gt; public function save($key =3D null, $urlVar =3D nu=
ll)<br>&gt;&gt; &nbsp;&nbsp;&nbsp; {<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&n=
bsp; &nbsp;&nbsp;&nbsp; // Check for request forgeries.<br>&gt;&gt; &nbsp;&=
nbsp;&nbsp; &nbsp;&nbsp;&nbsp; JRequest::checkToken() or jexit(JText::_('JI=
NVALID_=E2=80=8BTOKEN'));<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&=
nbsp; &nbsp;&nbsp;&nbsp; // Initialise variables.<br>&gt;&gt; &nbsp;&nbsp;&=
nbsp; &nbsp;&nbsp;&nbsp; $app =3D JFactory::getApplication();<br>&gt;&gt; &=
nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $lang =3D JFactory::getLanguage();<br>=
&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $model =3D $this-&gt;getMode=
l();<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $table =3D $model-&g=
t;getTable();<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $data =3D J=
Request::getVar('jform', array(), 'post', 'array');<br>&gt;&gt; &nbsp;&nbsp=
;&nbsp; &nbsp;&nbsp;&nbsp; $checkin =3D property_exists($table, 'checked_ou=
t');<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $context =3D "$this-=
&gt;option.edit.$this-&gt;=E2=80=8Bcontext";<br>&gt;&gt; &nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp;&nbsp; $task =3D $this-&gt;getTask();<br>&gt;&gt;<br>&gt;&gt; =
.....<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; // Validate the poste=
d data.<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Sometimes the =
form needs some posted data, such as for plugins<br>&gt;&gt; and modules.<b=
r>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $form =3D $model-&gt;getFo=
rm($data, false);<br>&gt;&gt;<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&n=
bsp; if (!$form)<br>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&gt=
;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $app-&gt;enq=
ueueMessage($model-&gt;=E2=80=8BgetError(), 'error');<br>&gt;&gt;<br>&gt;&g=
t; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return false;<b=
r>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&gt;&gt;<br>&gt;&gt; =
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Test whether the data is valid.<br=
>&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $validData =3D $model-&gt;v=
alidate($form, $data);<br>&gt;&gt;<br>&gt;&gt; .....<br>&gt;&gt;<br>&gt;&gt=
; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if ($validData =3D=3D=3D false)<br>=
&gt;&gt; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&gt;&gt; ....<br>&gt;&g=
t;<br>&gt;&gt; }<br>&gt;&gt;<br>&gt;&gt; As you can see in this function we=
 do:<br>&gt;&gt; $data =3D JRequest::getVar('jform', array(), 'post', 'arra=
y');<br>&gt;&gt;<br>&gt;&gt; and this is all ok, but the file is not sent i=
n the post array, but it is<br>&gt;&gt; in the $_FILES array.<br>&gt;&gt;<b=
r>&gt;&gt; And because of this the validation in the model fails.<br>&gt;&g=
t;<br>&gt;&gt; So as I said, I overwrote the save function and added a $dat=
a['kml_file']<br>&gt;&gt; =3D true; if the user has submitted a file.<br>&g=
t;&gt;<br>&gt;&gt; The question is - should I overwrite this function? Or s=
hould I do the<br>&gt;&gt; checks in the validate function?<br>&gt;&gt;<br>=
&gt;&gt; Since the validate function expects to receive the $form and the $=
data I<br>&gt;&gt; think that we should not do any interactions with the $_=
POST and $_FILES<br>&gt;&gt; arrays there, right?<br>&gt;&gt;<br>&gt;&gt; A=
m I doing something wrong here? Is there a better approach to this???<br>&g=
t;&gt;<br>&gt;&gt; Thanks in advance!<br>&gt;&gt; Daniel<br>&gt;&gt;<br>&gt=
;&gt; On Friday, March 23, 2012 10:27:04 PM UTC+1, elin wrote:<br>&gt;&gt;&=
gt;<br>&gt;&gt;&gt; I'm not sure I understand what is happening. Maybe you =
could show us your<br>&gt;&gt;&gt; code or xml?<br>&gt;&gt;&gt;<br>&gt;&gt;=
&gt;<br>&gt;&gt;&gt; Are you saying that the field has been filled out but =
the validation is<br>&gt;&gt;&gt; saying it is empty?<br>&gt;&gt;&gt;<br>&g=
t;&gt;&gt;<br>&gt;&gt;&gt; Elin<br>&gt;&gt;&gt;<br>&gt;&gt;&gt;<br>&gt;&gt;=
&gt; On Friday, March 23, 2012 11:39:22 AM UTC-4, Daniel D. / compojoom wro=
te:<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Hey Guys,<br>&gt;&gt;&gt;&gt; F=
or the last hour I've been trying to figure out how to use a<br>&gt;&gt;&gt=
;&gt; JFormFieldFile field that is set to required.<br>&gt;&gt;&gt;&gt;<br>=
&gt;&gt;&gt;&gt; The thing is when I save the form data, the save function =
complains that<br>&gt;&gt;&gt;&gt; the file field is empty and because it i=
s required -&gt; the validation<br>&gt;&gt;&gt;&gt; function returns false.=
..<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; I went around this by overriding=
 the whole save function in the<br>&gt;&gt;&gt;&gt; JControllerForm. (I jus=
t checked if the&nbsp; $_Files array contains the file and<br>&gt;&gt;&gt;&=
gt; added it to the $data array.) But this approach feels really stupid for=
<br>&gt;&gt;&gt;&gt; me??? I basically have the same save function + 3 line=
s that handle the file<br>&gt;&gt;&gt;&gt; field.<br>&gt;&gt;&gt;&gt;<br>&g=
t;&gt;&gt;&gt; Is there any other way to let JForm know that we have a fiel=
d that is<br>&gt;&gt;&gt;&gt; not in the post array? Preprocess form in the=
 controller or something?<br>&gt;&gt;&gt;&gt;<br>&gt;&gt;&gt;&gt; Regards,<=
br>&gt;&gt;&gt;&gt; Daniel<br>&gt;<br>&gt; --<br>&gt; You received this mes=
sage because you are subscribed to the Google Groups<br>&gt; "Joomla! CMS D=
evelopment" group.<br>&gt; To view this discussion on the web, visit<br>&gt=
; <a href=3D"https://groups.google.com/d/msg/joomla-dev-cms/-/Nc8IpWwUHz8J"=
 target=3D"_blank">https://groups.google.com/d/=E2=80=8Bmsg/joomla-dev-cms/=
-/=E2=80=8BNc8IpWwUHz8J</a>.<br>&gt;<br>&gt; To post to this group, send an=
 email to <a href=3D"mailto:joomla-dev-cms@googlegroups.com" target=3D"_bla=
nk">joomla-dev-cms@googlegroups.=E2=80=8Bcom</a>.<br>&gt; To unsubscribe fr=
om this group, send email to<br>&gt; <a href=3D"mailto:joomla-dev-cms%2Buns=
ubscribe@googlegroups.com" target=3D"_blank">joomla-dev-cms+unsubscribe@=E2=
=80=8Bgooglegroups.com</a>.<br>&gt; For more options, visit this group at<b=
r>&gt; <a href=3D"http://groups.google.com/group/joomla-dev-cms?hl=3Den-GB"=
 target=3D"_blank">http://groups.google.com/=E2=80=8Bgroup/joomla-dev-cms?h=
l=3Den-GB</a>.<br></p><p></p><p></p><p></p><p></p></blockquote>
------=_Part_82_29733976.1332679285687--

------=_Part_81_6152849.1332679285687--