I made a form containing file uploads via filepicker.
But I can not work with the files.
How do? following codes:
Form.php
require_once("$CFG->libdir/formslib.php"); class simplehtml_form extends moodleform { function definition() { global $CFG; $mform =& $this->_form; // Don't forget the underscore! $mform->addElement('hidden','id','0'); $mform->addElement('text', 'nome', get_string('nome_parceiro'), 'maxlength="100" size="91" '); $mform->addElement('htmleditor', 'descricao', get_string('descricao'), 'wrap="virtual" rows="40" cols="50"'); $mform->addElement('filepicker', 'image', get_string('files')); $buttonarray=array(); $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges')); $buttonarray[] = &$mform->createElement('cancel'); $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); $mform->closeHeaderBefore('buttonar'); } // Close the function }
File edit.php
require_once('form.php'); $mform = new simplehtml_form();//name of the form you defined in file above. //default 'action' for form is strip_querystring(qualified_me()) $p = optional_param('p', null, PARAM_INT); if (!empty($p)) { if ($idparceiro = $DB->get_record_sql('SELECT * FROM {parceiros} WHERE id='.$p)) { $mform->set_data($idparceiro); $mform->display(); } else { echo 'Não foi possível localizar'; } } else { if ($mform->is_cancelled()){ //you need this section if you have a cancel button on your form //here you tell php what to do if your user presses cancel //probably a redirect is called for! redirect($CFG->wwwroot.'/a'); } else if ($fromform=$mform->get_data()){ $par = new stdClass(); $par->id = $fromform->id; $par->nome = $fromform->nome; $par->descricao = $fromform->descricao; $par->image = $fromform->image; if ($par->id != 0) { if (!$DB->update_record('parceiros', $fromform)) { print_error('Erro ao atualizar'); } else { echo 'Alterado com sucesso'; } } else { $newid = $DB->insert_record('parceiros', $par); echo 'Inserido sobre id numero: '.$newid.''; } } else { $mform->display(); } }
How to fix? and then how to view files?