|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Techniques for Sequence of PagesHowdy,
I searched the Knop archive for help, but came up empty with "step", "next" and "sequence". I would like to have a sequence of forms that progress through ordered steps, sort of like a survey. The steps must be performed in order. A user may resume where they left off. Each step has some validation logic. How would I implement this using Knop? Handling the failure is no problem: just reload the form. But for the success, I'm trying to figure out the best way to load the next Knop form in the sequence. First, I assume that the application logic should go into the action file, correct? If so, then here is some sample code I pulled from the Knop demo files. _action/act_advanced_edit.inc ----------------------------- if($f -> isvalid); // edited for brevity // add record // update session variable // uhh.... magic? use an include or redirect_url? /if; if: (!($f -> isvalid) || $f -> error_code) && ($f -> getbutton == 'add' || $f -> getbutton == 'save'); // remain on the same path to show form again $nav -> (setlocation: ($nav -> actionpath)); // show error message $message -> (insert: ($f -> error_msg) + ' ' + ($f -> error_code)); /if; If I understand that correctly, then the value of the -formaction parameter in the knop form object in the config file determines what is the next page in the sequence: _config/cfg_advanced_edit.inc ----------------------------- var: 'f'=(knop_form: -formaction=($nav -> (url: 'advanced')), // action attribute for the html form -method='post', -database=$d, -actionpath='advanced/edit', // framework action path Is -formaction the "magic" that tells Knop what to load next? --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/ |
|
|
Re: Techniques for Sequence of PagesAt 06.28 -0700 2009-06-29, Steve Piercy - Web Site Builder wrote:
>First, I assume that the application logic should go into the action file, correct? The application logic to take care of the form input, correct. >If so, then here is some sample code I pulled from the Knop demo files. > >_action/act_advanced_edit.inc >----------------------------- > > if($f -> isvalid); // edited for brevity > // add record > // update session variable > // uhh.... magic? use an include or redirect_url? Nothing magic at all since -formaction tells where to go next. > /if; > > if: (!($f -> isvalid) || $f -> error_code) > && ($f -> getbutton == 'add' || $f -> getbutton == 'save'); > // remain on the same path to show form again > $nav -> (setlocation: ($nav -> actionpath)); > // show error message > $message -> (insert: ($f -> error_msg) + ' ' + ($f -> error_code)); > /if; > >If I understand that correctly, then the value of the -formaction parameter in the knop form object in the config file determines what is the next page in the sequence: Correct, -formaction is what you see in the url after submitting. If the validation fails then the current path does not correspond to the -formaction (or the url) since the path is reverted to the previous form by ->setlocation. >Is -formaction the "magic" that tells Knop what to load next? That is totally correct, and this is exactly what I'm trying to say with the "Knop Application Flow" description in the Knop manual (page 15). 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; -- Johan Sölve [FSA Member, Lasso Partner] Web Application/Lasso/FileMaker Developer MONTANIA SOFTWARE & SOLUTIONS http://www.montania.se mailto:joh-n@... (spam-safe email address, replace '-' with 'a') -- ############################################################# 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/ |
|
|
Re: Techniques for Sequence of PagesOn Tuesday, June 30, 2009, inbox_js@... (Johan Solve) pronounced:
>Now, on to a different way to handle multistep forms. Thanks for all the reassurance and nudge in the proper direction. I'm on my way! --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/ |
|
|
Re: Techniques for Sequence of PagesOn 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/ |
|
|
Re: Techniques for Sequence of PagesAt 08.31 -0700 2009-07-08, Steve Piercy - Web Site Builder wrote:
>I'm having trouble with this example. It appears that after a redirect, there is no -actionpath. The -actionpath for all steps should be the same. However, -formaction needs to be $nav -> url + $checkout_stage. That was a little loophole in my explanation, sorry about that... :-) Remember, all steps are technically on the same nav path. You shouldn't define the different steps in the nav. So with my example checkout/1 checkout/2 checkout/3 there is only one "checkout" nav item. The steps 1, 2 and 3 are not part of the defined Knop navigation, but are handled as path leftovers (getargs). Hope this helps... -- Johan Sölve [FSA Member, Lasso Partner] Web Application/Lasso/FileMaker Developer MONTANIA SOFTWARE & SOLUTIONS http://www.montania.se mailto:joh-n@... (spam-safe email address, replace '-' with 'a') -- ############################################################# 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/ |
| Free embeddable forum powered by Nabble | Forum Help |