Ajax to display multiple error messages. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Ajax to display multiple error messages. (/showthread.php?tid=64797) |
Ajax to display multiple error messages. - wolfgang1983 - 03-26-2016 I have a multiple upload function using json, on my view each file that has a error should display the file upload error message. I can see that if I upload 3 images and all 3 images have errors only 2 of the messages will display on the view. I use ajax to submit my form. How can I make sure that if all 3 images would display error messages for all 3 rather than just 2 on view. Ajax Script Code: <script type="text/javascript"> Function PHP Code: public function upload() { RE: Ajax to display multiple error messages. - Tpojka - 04-02-2016 You don't need this part at all: PHP Code: if (!$json) { since $json will always be not true. Also, you want to save error for every not uploaded file so correct nesting would be: PHP Code: if ( ! $this->upload->do_upload($fieldname)) After that what is left is to save success message if all files are uploaded with no errors: PHP Code: if ((int)$check_if_any_error < 1)//or alternatively if (count($json['error']) < 1) Then, handle response well as you get (if any) array for errors. |