I just realized that I've posted this maybe in the wrong group (general joomla dev would have been a better match, maybe).
Thanks for the reply Elin. Of course I can share a little bit of code:
so here is the form:
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset>
<field name="hotspots_kml_id" type="text" default="0" label="JGLOBAL_FIELD_ID_LABEL"
readonly="true" class="readonly"
description="JGLOBAL_FIELD_ID_DESC"/>
....
<field name="kml_file" type="file" label="COM_HOTSPOTS_KML_FILE"
description="COM_HOTSPOTS_KML_FILE_DESC" required="true"/>
....
</fieldset>
</form>
my edit.php layout file:
<form enctype="multipart/form-data" action="<?php echo JRoute::_('index.php?option=com_hotspots&view=kml&hotspots_kml_id=' . (int)$this->item->hotspots_kml_id); ?>" method="post" class="form" name="adminForm" id="adminForm" >
<div class="width-60 fltlft">
<fieldset class="adminform">
<legend><?php echo empty($this->item->hotspots_kml_id) ? JText::_('COM_HOTSPOTS_NEW_KML') : JText::sprintf('COM_HOTSPOTS_EDIT_KML', $this->item->hotspots_kml_id); ?></legend>
<ul class="adminformlist">
....
<li>
<?php echo $this->form->getLabel('hotspots_kml_id'); ?>
<?php echo $this->form->getInput('hotspots_kml_id'); ?>
</li>
....
<li>
<?php echo $this->form->getLabel('kml_file'); ?>
<?php echo $this->form->getInput('kml_file'); ?>
</li>
</ul>
.....
<input type="hidden" name="task" value=""/>
<?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 = null, $urlVar = null)
{
// Check for request forgeries.
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Initialise variables.
$app = JFactory::getApplication();
$lang = JFactory::getLanguage();
$model = $this->getModel();
$table = $model->getTable();
$data = JRequest::getVar('jform', array(), 'post', 'array');
$checkin = property_exists($table, 'checked_out');
$context = "$this->option.edit.$this->context";
$task = $this->getTask();
.....
// Validate the posted data.
// Sometimes the form needs some posted data, such as for plugins and modules.
$form = $model->getForm($data, false);
if (!$form)
{
$app->enqueueMessage($model->getError(), 'error');
return false;
}
// Test whether the data is valid.
$validData = $model->validate($form, $data);
.....
if ($validData === false)
{
....
}
As you can see in this function we do:
$data = JRequest::getVar('jform', array(), 'post', 'array');
and this is all ok, but the file is not sent in the post array, but it 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 $data['kml_file'] = 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 $_FILES arrays there, right?
Am I doing something wrong here? Is there a better approach to this???
Thanks in advance!
Daniel