Re-populate a page with multiple forms if one form fails validation - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Re-populate a page with multiple forms if one form fails validation (/showthread.php?tid=52557) |
Re-populate a page with multiple forms if one form fails validation - El Forum - 06-15-2012 [eluser]it.peds[/eluser] First, thank everyone reading this. A site that has a search form/widget shows on every page. In case of user is filling a different form, and suddenly he/she want to search something else; if the search returns no results, besides loading a error page, any suggestion for how to re-populate this page with both forms as before but with a error message? I have client-site validation and ajax ways to solve this problem, but I would like to learn a way when javascript is turned off. Feel free to leave any idea. Thank you for your help in advance. Re-populate a page with multiple forms if one form fails validation - El Forum - 06-15-2012 [eluser]dnc[/eluser] The way I do my validations is this. 1. Say your form is at site/search. The do a Code: echo form_open('site/search'); to post the data back to self. This is equivalent to $_SERVER['PHP_SELF']; In your model or controller that checks the query you need to check if form was empty or whatever and I would use: Code: $data['error_message'] = $this->session->set_flashdata('search_query', 'Error Message Here'); You will probably want a view that solely consists of your form or maybe a header view with the form so you will not reload the entire page on an error. Post the flash_data to the view. I hope this is clear to you. Re-populate a page with multiple forms if one form fails validation - El Forum - 06-15-2012 [eluser]it.peds[/eluser] @dnc, First, thank you very much. I think you mean Code: redirect('controller/otherForm', 'refresh'); In this case, the un-saved data of the other form will not be re-populated. Re-populate a page with multiple forms if one form fails validation - El Forum - 06-15-2012 [eluser]dnc[/eluser] [quote author="it.peds" date="1339796689"]@dnc, First, thank you very much. I think you mean Code: redirect('controller/otherForm', 'refresh'); In this case, the un-saved data of the other form will not be re-populated.[/quote] Is there a reason you do not want to use the form validation class to re-populate the form? Code: value="<?php echo set_value('search_value');?>"> Why use refresh here, this is where you need to pass your flash_data Code: redirect('controller/otherForm', $data); Re-populate a page with multiple forms if one form fails validation - El Forum - 06-15-2012 [eluser]it.peds[/eluser] @dnc, My problem, as topic suggests, is when one form fails form_validation, how can I re-populate a page with multiple forms with all un-saved data and no javascript? So far, using redirect(), I can re-populate all forms with saved data and error, but not unsaved one. Beware, un-saved data can be any forms on the page. Re-populate a page with multiple forms if one form fails validation - El Forum - 06-15-2012 [eluser]Sanjay Sarvaiya[/eluser] For re-populate all forms. You can do with passing POST data to view after form validation false. Code: if(count($_POST) > 0) may thats help you. |