Split form in many pages... better way? - 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: Split form in many pages... better way? (/showthread.php?tid=52913) Pages:
1
2
|
Split form in many pages... better way? - El Forum - 07-03-2012 [eluser]Aken[/eluser] [quote author="CroNiX" date="1341255594"]If you are going to store the previous data in hidden fields, wouldn't that mean you are going to constantly be revalidating the same data, and an ever increasing amount for each step that you progress through?[/quote] +1 - Do NOT use hidden fields, they can be manipulated. Don't trust your users. Split form in many pages... better way? - El Forum - 07-03-2012 [eluser]Lewis Cowles[/eluser] you could have the entire form on a single page inside a div with overflow: hidden; in the css and use Code: <a name="section1">... Also check out how Magento does this; It's the same thing, but with jQuery animations to toggle between fieldsets, for that little extra visual flair. very very nice to be able to add this kind of functionality. Also as a N.B. consider that the form should be external to the div's Code: <form ...><div ...>content...</div></form> Split form in many pages... better way? - El Forum - 07-03-2012 [eluser]henry178[/eluser] the "hidden fields" must be controlled in every controller; because these could be manipulate. How can I do? Split form in many pages... better way? - El Forum - 07-03-2012 [eluser]henry178[/eluser] ps I have also image fileds. Split form in many pages... better way? - El Forum - 07-03-2012 [eluser]cartalot[/eluser] another approach - validate the data and update the database with each form lots of reasons but start with the user of your forms you need to validate the data from each form on the server before submitting to database so if there is a validation problem with form 1 you want to stop the process right there, kick back form 1 and have them fill it out correctly before going to form 2, etc sessions and cookies are necessary sometimes, but for a multistep form - you have the perfect reason NOT to bother with them. one hidden form field can contain a unique id - that use each in form. for example, in your database table have a varchar field: uniqueid in your controller BEFORE the first form is called generate a unique id, this example generates a 10 character id Code: $['data']uniqueid = random_string( 'alnum', 10 ); and then in your form have a hidden field with the unique id value Code: echo form_hidden('uniqueid', $uniqueid ); validate the data from form 1 insert the uniqueid and form 1 to database in the controller pass uniqueid value to -> $['data']uniqueid so then its available for form 2 etc etc then use that uniqueid to do the updates with each form in other words, you wont need the record or row 'id' which you would typically use for an update no cookies, no sessions, no problems :-) Split form in many pages... better way? - El Forum - 07-03-2012 [eluser]Lewis Cowles[/eluser] well in order to have the code handled by multiple controllers, you can simply post the data to the url for the controller and output a field in the view. Code: $data['savedFieldData'] = ""; By doing this in a model you would also have the code in the controller cut down dramatically keeping your controllers and views skinny. Split form in many pages... better way? - El Forum - 07-03-2012 [eluser]PhilTem[/eluser] To avoid manipulation of data you could just add an encoded string that matches the previous form's post data to your new form. That means: Code: // In controller of second form display method And for validation you can easily run it as Code: $previous_previous_form = $this->input->post('hidden_input'); This process can be done over and over again for each form page except you have to generate new tokens and take the right post fields into your hidden input. NOTE However, I do not recommend to use this (see posts above). I'd really store all data in a flat file or db. It is just shown by me since you were asking which ways there are and I am solely elaborating one of the possible ways PS: I really tried auto-completing some code parts using ctrl+space... But unfortunately these forums don't have auto-completion Split form in many pages... better way? - El Forum - 07-06-2012 [eluser]henry178[/eluser] In controller 1: Code: data for the view... In controller 2: //last controller called from the action form Code: data for the view... but so I must repeat in controller 2 the same code of controller 1; is it correct? Split form in many pages... better way? - El Forum - 07-06-2012 [eluser]cartalot[/eluser] >but so I must repeat in controller 2 the same code of controller 1; is it correct? its possible to do that way, but typically if you have something like a 3 part form -- you would do it from the same controller just use different method (function) names like function validform() function validformtwo() function validformthree() so if your class is 'register' the first form will direct to "register/validform" second form goes to "register/validformtwo" Split form in many pages... better way? - El Forum - 08-18-2014 [eluser]mariepizzer[/eluser] Thank you so much, this worked for me. I opened the form before echoing $content and everything was ok (afaik). [quote author="henry178" date="1341568762"]In controller 1: Code: data for the view... [/quote] |