Welcome Guest, Not a member yet? Register   Sign In
Multi-Step Form Data
#11

[eluser]maadmac[/eluser]
[quote author="BrandonDurham" date="1194132763"]When creating a multi-step form (specifically a form broken up into three steps/pages) is it a bad idea to create a session variable containing the form data to carry it between pages?[/quote]

No, it's not bad "form" at all... that's precisely why sessions exist. I'm working on exactly the same thing right now, and when it comes to multistep forms, with CI you have basically 3 options:

1. Store the user data as a session cookie
2. Store the user data in the session but write them to the db
3. Treat the multistep form as separate forms, and store each page's results in the db

For #1, this is great so long as you're not storing >4kb. One of CI's limitations is that session userdata are not written to the db, though Mr Allard promises us that this is forthcoming. In the meantime, there are some excellent 3rd party options that will do that, which brings us to #2. I like OBSession, personally, but like many of the best CI developers, Oscar has jumped ship for Kohana and so there is no further development on it.

#3 is my recommendation and is really easy to implement in CI. (walesmd has answered this question like a dozen times in the forum, hunt around a little bit and you'll find it.) In my case, I have a temporary table called 'cart' that stores each page's worth of POST data -- as the user goes page by page, just keep writing it to the table. All you'll need to do is the store the item's ID in the session so you can perform the db lookup. If they want to make any changes, you do it all in that table.

Finally, when everything's ready to go, commit the data in 'cart' to 'orders' and flush the info from 'cart'. So that table acts as a staging area... This is the approach I used for a recent shopping cart-like app and it works simply and easily.

Cheers
#12

[eluser]BlueCamel[/eluser]
What about integrating the PEAR QuickForms class into your controller and view? I've used this before, outside of CI, however I expect to be using it with a CI project I'm working on now. Oh, the QuickForm class has a multi-step wizard example.
#13

[eluser]mwmerz[/eluser]
I think i'm going to move more toward using some sort of ajax stuff to do my form processing. I've found it a little more user friendly to split up multi-part forms into their own little forms and process them with ajax. But now production on my current project has halted a little because i'm obsessed with doing my CRUD right. I need to decide on a framework i like for the JS stuff (leaning towards script.aculo.us) and come up with an easy, readable way to roll the whole thing out. I'll definitely check out the xajax example.

Thanks for help
#14

[eluser]maadmac[/eluser]
I feel obligated to make a plug for jQuery... it's not as a slick a brand as Mootools or Prototype, but having dabbled in all three I find it head and shoulders above the rest!

Cheers
#15

[eluser]mwmerz[/eluser]
Yeah, i'm trying out Jquery, YUI, etc. I know each package has its own thing. The only reason i'd lean towards script.aculo.us is because i think i saw derek allard say somewhere that he is going to work on integration within CI vs. mootools.
#16

[eluser]Unknown[/eluser]
I've used a pure PHP solution in the past that has worked great. Super simple to implement.

Code:
<?php
  // Loop through the POST variables passed from the previous page
  foreach ($_POST as $key => $value) {

    // Decode the POST variable
    $value=htmlentities(stripslashes(strip_tags($value)));

    // Create a hidden input containing the value
    echo "<input type=\"hidden\" name=\"" . $key . "\" value=\"" . $value . "\" />\r\n";
  
  }
?>

This will create hidden inputs for all the variables passed to the page from the previous page. Copy and paste this on each page of your form and all the variables from the previous page(s) will be passed.

NOTE: This assumes your form is using the POST method. Change the code accordingly if you're using GET. Also, you may want to escape specific variables. For example, the "submit" variable. To do this, add an IF statement inside the FOREACH as follows:

Code:
if ($key!="submit"){
      
  // Decode the POST variable
  $value=htmlentities(stripslashes(strip_tags($value)));

  // Create a hidden input containing the value
  echo "<input type=\"hidden\" name=\"" . $key . "\" value=\"" . $value . "\" />\r\n";

}

Hope this help!


Oops - I should've read you post in more detail. I guess you don't want to use the POST hidden field method.
#17

[eluser]saiya[/eluser]
can you give an example with with text inputs to understand how you can use the foreach/hidden input method when dealing with say a 3 slide/step form?
#18

[eluser]Unknown[/eluser]
Brett DeWoody thank you so much, your solution helped me, and saved my time, thank u.




Theme © iAndrew 2016 - Forum software by © MyBB