[eluser]borgir[/eluser]
Hey there!
Sorry to bother you guys with the same issue...
I'm basing my validation on PistolPete's example and I'm always presented with the message:
"O campo Imagem é obrigatório." which means: "The image field is required."
Controller:
Code:
function enviar() {
$this-> validate_form();
}
function validate_form() {
$this->form_validation->set_error_delimiters('<p style="color:red;">', '</p>');
$this->form_validation->set_rules('assunto', 'Assunto', 'trim|required|max_length[50]');
$this->form_validation->set_rules('descricao', 'Descrição', 'trim|required');
$this->form_validation->set_rules('userfile', 'Imagem', 'required|callback__do_upload');
if ($this->form_validation->run() == FALSE) {
$data['main_content'] = 'newsletter/newsletter_create_view';
$this->load->view('includes/template', $data);
} else {
}
}
function _do_upload($file) {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '3000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if (!$this->upload->do_upload())
{
$this->form_validation->set_message('_do_upload', $this->upload->display_errors());
return FALSE;
} else {
return TRUE;
}
}
View:
Code:
<?php echo utf8_encode(form_error('assunto')); ?>
<?php echo utf8_encode(form_error('descricao')); ?>
<?php echo utf8_encode(form_error('userfile')); ?>
<form method="post" action="<?php echo site_url() . '/newsletter/enviar'; ?>" enctype="multipart/form-data">
<input type="text" name="assunto" value="<?php echo set_value('assunto'); ?>" size="60" />
<textarea name="descricao" rows="3" cols="74"><?php echo set_value('descricao'); ?></textarea>
<input type="file" name="userfile" />
<input type="submit" value="GUARDAR">
</form>
Can anyone give me a hint?
Thks a lot!!