guizmo
guizmo

Reputation: 105

Multiple file input and form validation?

I have multiple files and input text in my form. My code is :

if(formValidationIsGood) {
   if(customeCheckFileErrorIsEmpty) {
      //StartProcess
   }
   else {
    //I load my view with my array which contains the different error related to the files.
   }
else {
    //I load my view with the form error (set up by : $this->form_validation->set_rules('variable', 'Variable', 'required');) But if there is an error for the files I cant display it.
}

With this code I can't show the form error and the files error at the same time. For example the user, is uploading an csv file instead of a pdf file, and he forgot to write into a text input, the form error will be displayed but not the file error and vice versa.
Obviously I am using the helper file provide by code igniter.

Upvotes: 0

Views: 38

Answers (1)

Javier Larroulet
Javier Larroulet

Reputation: 3237

Since you want to display error messages for either A OR B, you can try this:

if (!formValidationIsGood || !customeCheckFileErrorIsEmpty)
{
  // load the view and display whatever errors you found
}

else
{
  // form validation IS good and the files error is empty
}

The if clause above will evaluate to true if either formValidationIsGood ISN'T true (the ! prefix is key) OR the customeCheckFileErrorIsEmpty ISN't true (which would mean there is an error)

Upvotes: 2

Related Questions