Codeigniter blog application bug: form is loaded without validation errors - 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: Codeigniter blog application bug: form is loaded without validation errors (/showthread.php?tid=72555) |
Codeigniter blog application bug: form is loaded without validation errors - Ajax30 - 01-05-2019 I am working on a blogging application in Codeigniter 3.1.8 and Bootstrap 4. I have an "Edit post" form with validation. Code: <?php echo form_open_multipart(base_url('posts/update')); ?> If validation fails (because the Title field has been emptied, for example), the form should reload *with validation errors*. My `update()` (lives in the Posts controller) method is wrong: it uses a redirect, so the form is reloaded **without** validation errors, to its initial state. PHP Code: public function edit($id) { I am almost certain the problem is this line: Code: redirect('/posts/edit/' . $slug); What shall I change? RE: Codeigniter blog application bug: form is loaded without validation errors - jreklund - 01-05-2019 You need to combine edit and update. If you look at my example below I'm saving it inside run() and loading the form inside "else". PHP Code: public function update( $group_id ) RE: Codeigniter blog application bug: form is loaded without validation errors - natanfelles - 01-06-2019 Also is possible save the validation errors as session flashdata. After the redirect, check if has errors and get them. This: https://en.wikipedia.org/wiki/Post/Redirect/Get |