I have multiple custom file inputs in my module , id like to save all this inputs in my database table ("Custom table , not the Joomla tables") , below is my code , which saves only 1 input , there are 4 inputs :
helper.php
class moduploaddocumentsHelper
{
/**
* Retrieves the hello message
*
* @param array $params An object containing the module parameters
*
* @access public
*/
public static function getdata()
{
//Retrieve file details from uploaded file, sent from upload form
$file = JRequest::getVar('highestacademic', null, 'files', 'array');
//Import filesystem libraries. Perhaps not necessary, but does not hurt
jimport('joomla.filesystem.file');
//Clean up filename to get rid of strange characters like spaces etc
$filename = uniqid().JFile::makeSafe($file['name']);
//Set up the source and destination of the file
$src = $file['tmp_name'];
$dest = JPATH_BASE . DS . "media" . DS ."documents" . DS . $filename;
// $name=$post['highestacademic']['name'] ;
//First check if the file has the right extension, we need jpg only
if ( strtolower(JFile::getExt($filename) ) == 'jpg' || strtolower(JFile::getExt($filename) ) == 'png') {
if ( JFile::upload($src, $dest) ) {
$user = JFactory::getUser();
$useid = $user->id ;
// Obtain a database connection
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Insert columns.
$columns = array('user_id', 'document_name');
// Insert values.
$values = array($useid, $db->quote($filename) );
// Retrieve the shout
$query
->insert($db->quoteName('#__documents'))
->columns($db->quoteName($columns))
->values(implode(',', $values));
$db->setQuery($query);
$db->execute();
JFactory::getApplication()->enqueueMessage(JText::_('DOCUMENT SUCCESFULLY UPLOADED'), 'Message');
} else {
echo "error !"; //Redirect and throw an error message
}
} else {
echo "Wrong extension !"; //Redirect and notify user file is not right extension
}
return $dest ;
}
}
/tmpl/default.php
<form method="post" enctype="multipart/form-data" >
<div class="form-group">
<label for="highestacademic">Attachment of Highest Academic Qualifications</label>
<input name="highestacademic" type="file" id="highestacademic">
<p class="help-block">Degree, Diploma, Pre-University, GCE O-Levels, etc.</p>
</div>
<div class="form-group">
<label for="language">Attachment of Language Qualifications</label>
<input name="language" type="file" id="language">
<p class="help-block">TOEFL, IELTS , etc.</p>
</div>
<div class="form-group">
<label for="passport">Attachment of Passport Copy</label>
<input name="passport" type="file" id="passport">
<p class="help-block">ID or Passport copies both sides.</p>
</div>
<div class="form-group">
<label for="supporting">Other Supporting Documents</label>
<input name="supporting" type="file" id="supporting">
<p class="help-block">Other supporting documents ie photos ,etc .</p>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>