need helping making POST data last for several page refreshes, so user can confirm data |
[eluser]Flying Fish[/eluser]
There may be a better way of going about this. I'm pushing the limits on my php skills here. So here's the scenario, a user submits a valid form, then they review the data they submitted and can either 1. go back and make changes, or 2. confirm their data is correct My questions are 1. I have all the users POST data for the confirmation page, but how do I repopulate the form if they choose to go back? 2. If they confirm their data, how do I write it all into the database? Here is the controller. Code: function add_info() Here's the view file for 'order_review' Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> I'm attaching the view 'order_add_info' as a zip file Let me kno if I can clarify any of this. Thanks!
[eluser]TheFuzzy0ne[/eluser]
You can store the previous pages in the form using hidden inputs. You can either use the values as the second parameter for set_value() or you could shuffle them about, like this: Page 1 Code: <input type="text" name="field1" value="<?php echo set_value('field1'); ?>" /> <!-- Active --> Page 2 Code: <input type="hidden" name="field1" value="<?php echo set_value('field1'); ?>" /> <!-- Hidden --> Page 3 Code: <input type="hidden" name="field1" value="<?php echo set_value('field1'); ?>" /> <!-- Hidden --> Hopefully this makes sense. As the data will already be in the post array, this can be used to force validation of the data (to be sure the data is valid and hasn't been changed by the user), on a page that's being returned to.
[eluser]JoostV[/eluser]
You could try to serialize the $_POST array, using serialize(). Serialize() converts your $_POST array into a string that you can store virtually anywhere. You can then store this serialized POST array into flashdata. On the new page, take the flashdata, unserialize it, using unserialize(), and use it to populate your form. Haven't tested it, but it should work.
[eluser]bretticus[/eluser]
You can always post the view to itself and just print the users responses above the same form if you detect post data. You would also just change the id/name on the submit button and handle it differently on the repost. Any of these ways mentioned will work though. You may want to note that: Code: <div><h3>State</h3><?=$this->input->post('where_state', TRUE)?></div> is safer than Code: <div><h3>State</h3><?=$_POST['where_state'];?></div> If have no idea what you're building, and this may just be a registration form, but I am generally never fond of allowing content on my pages that have not been filtered for xss attacks.
[eluser]vickel[/eluser]
I've just been into this (post data for several pages): hidden input fields work fine (I'm not going to put somebodies data into my database, unless it's serious business), and I also use the form validation class @ http://ellislab.com/codeigniter/user-gui...ation.html there is this very helpful concept: controler: Code: $this->form_validation->set_rules('first_name', 'First Name', 'required|alpha_dash'); view: use the set_value() [or set_checkbox(), etc.] function to repopulate the form hope this makes sense Vickel
[eluser]Flying Fish[/eluser]
Thanks all, I'm going to look at these options and try to implement one. I'll try to post back here when I get it working.
[eluser]Flying Fish[/eluser]
One final post in case it helps anybody in the future. Hidden form fields was the the go for me!
[eluser]simshaun[/eluser]
Depending on the situation, I usually use sessions. Also, you don't have to serialize the POST array to put it in the session. |
Welcome Guest, Not a member yet? Register Sign In |