[eluser]Référencement Google[/eluser]
Hi,
I have a piece of code that I am sure can be a lot more simpler and smart but need your advices about it.
What I am trying to do is I have a form handling user datas like Name, Surname, ...
In the same form, I have an image upload. The problem is that I am not really sure how to handle the form submiting with the 2 forms together, so here is the controller code (part that handle form submission):
Code:
// If the form is posted, run the form validation
if($this->validation->run())
{
// All ok ? We check now for the photo upload
$this->files = $this->photo_upload();
if(!$this->files)
{
if($this->upload->display_errors('<p class="form_error">', '</p>'))
{
$data['upload_message'] = $this->upload->display_errors('<p class="form_error">', '</p>');
}
else
{
$data['upload_message'] = '<p class="form_error">You did not select any file on your computer !</p>';
}
$data = $this->display_formUpload($data);
$this->display_form($data);
}
else
{
// All was fine, upload OK. We send the email and redirect
if($this->_send_email())
{
redirect('userform/success');
exit;
}
else
{
// The email couldn't been sent or there was another problem.
$data['upload_message'] = '<h1 class="error">There was a problem while submiting your datas.</h1>';
}
}
As you can see, I made the form validation in 2 steps, first validate the form datas, then validate the upload. Any help on doing this in a better way?