« Return to Thread: Techniques for Sequence of Pages

Re: Techniques for Sequence of Pages

by Steve Piercy :: Rate this Message:

Reply to Author | View in Thread

On Tuesday, June 30, 2009, inbox_js@... (Johan Solve) pronounced:

>Now, on to a different way to handle multistep forms.
>
>URL examples:
>checkout/1
>checkout/2
>checkout/3
>
>In this case only "checkout" is defined in the nav object, so the 1, 2 and 3 are
>"leftovers" after nav->getlocation  is called. The first leftover is returned by
>nav->getargs(1), for example 1, 2 or 3.
>Using the same nav path for all steps means that the same set of config, lib, content
>and action files are used for all the steps, so inside each of them there is a
>select/case tree that looks at getargs(1) and produces the appropriate result for each
>step. This is useful for multistep forms where some or much of the logic can be reused
>between steps.
>
>The form for each step uses the same -formaction as -actionpath, which is a bit
>contrary to the above description. So the form doesn't actually advance to the next
>step upon submission, but instead the action file redirects to the next step if the
>submission is successful. This gives clean URLs that correspond to the actual current
>step in the multistep form no matter if the form is successful or not, and it also
>makes it really easy to go backwards in the chain simply by redirecting to the
>previous step. The form posts are also "refresh safe" that way.
>With this method it's also easy to handle multistep forms that branch off or skip
>steps.
>
>
>Some code samples that hopefully illustrates this
>
>
>config_checkout.inc (just the beginning)
>-------------------
>var('checkout_stage'=1);
>if($nav -> getargs -> size && $nav -> getargs(1) -> size);
>   $checkout_stage = integer($nav -> getargs(1));
>/if;
>
>var('ordersent'=false);
>
>// then configure some forms depending on current $checkout_stage
>// ...
>
>
>action_checkout.inc (sample code)
>-------------------
>var('continue'=true);
>
>// handle abnormal flow first
>if(action_param('button_prev') -> size);
>   // Got to previous step
>   $continue=false;
>   redirect_url(($nav -> url ) + ($checkout_stage - 1));
>/if;
>
>
>// perform actions
>select($checkout_stage);
>case(1);
>   // update cart contents
>   // ...
>case(2);
>   // update shipping and payment details  
>   // ...
>case(3);
>   if($continue);
>       // add order
>       inline($db_connect);
>       var('updatefields'=$s_checkoutform -> updatefields);
>       $db_order -> addrecord($s_checkoutform -> updatefields);
>
>       var('order_id'=$db_order -> keyvalue);
>      
>       if($db_order -> error_code);
>           $continue = false;
>           $message_form -> insert('error'='COuld not cerate order ');
>       /if;
>
>       if($continue && $order_id > 0);
>           // add order items
>           // ...
>       /if;
>       $ordersent = true;
>
>       /inline;
>   /if;
>/select;
>
>// follow normal flow
>if(action_param('button_next') -> size
>   && $checkout_stage < 3
>   && $continue);
>   // Go to next step
>   redirect_url(($nav -> url ) + ($checkout_stage + 1));
>/if;

I'm having trouble with this example.  It appears that after a redirect, there is no -actionpath.

Everything in steps 1 and 2 are identical, except for the necessary logic to advance the form with a redirect.

There is simple validation on each form.  On the first form when I enter bad data, I get error messages and stay on the form.  On the second form when I enter bad data, I don't get any error messages and stay on the form.

For the first form, I get a hidden input when I view HTML source:

    <input type="hidden" name="-action" value="step1">

But on the second form, that hidden input is not present.

Here are my form declarations:

    var('f' =
        knop_form(
            -formaction=($nav -> url), // real URL path
            -method='post',
            -actionpath=($nav -> path), // framework action path
            -legend=$lang_ui -> step1,  // step2 for step 2
            -errorclass = 'error_label')
    );

I must have tried every permutation possible for -formaction and -actionpath, including hard-coding strings, but I've gotten nowhere.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy               Web Site Builder               Soquel, CA
<web@...>                  <http://www.StevePiercy.com/>

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

 « Return to Thread: Techniques for Sequence of Pages