Writing a D6 module. I'm trying to build a lengthy form, where at some point, towards the bottom of the form, it would be nice to (1) optionally hit an 'incomplete'/branch submit handler, (2) cache the interim curent form state, (3) double redirect to a new form (create submit ) etc (4) bounce back to the original (with second redirect), (5) reload interim state from the cache, (6) amend with new details gleaned from the intermediate/branch form, (7) finally proceed to the "complete" form submit handler of original form
Currently I can double redirect to a second form, but on bounce back, all the original details are lost, which is really unintuitive to the user, who thinks they've already filled out that part.
I guess I need to do something like this:
function mymodule_interim_submit($form, &$form_state) { $form_build_id = $form_state['values]['form_build_id']; unset($form_state['submitted']); unset($form_state['storage']); // $form_state['rebuild'] = FALSE; $form_state['saved']= $form_state['values]; $form_state['redirect'] = array ( // double redirect 'mymodule/intermediate_form', 'mymodule/this_form/' . $form_build_id ); }
But I don't know if thats sufficient to preserve the interim state of the form, or will it still be deleted from the cache after the interim_submit completes, or ...(barking up wrong tree)?
thanks Doug
This message might be better for the development list rather than the support list.
Would crafting the entire form as a single multi-step work for you? Consider this example: http://www.benjeavons.com/multi-step-forms-drupal-6-using-variable-functions
On Mon, Nov 22, 2010 at 4:31 PM, Doug doug.duboulay@gmail.com wrote:
Writing a D6 module. I'm trying to build a lengthy form, where at some point, towards the bottom of the form, it would be nice to (1) optionally hit an 'incomplete'/branch submit handler, (2) cache the interim curent form state, (3) double redirect to a new form (create submit ) etc (4) bounce back to the original (with second redirect), (5) reload interim state from the cache, (6) amend with new details gleaned from the intermediate/branch form, (7) finally proceed to the "complete" form submit handler of original form
Currently I can double redirect to a second form, but on bounce back, all the original details are lost, which is really unintuitive to the user, who thinks they've already filled out that part.
I guess I need to do something like this:
function mymodule_interim_submit($form, &$form_state) { $form_build_id = $form_state['values]['form_build_id']; unset($form_state['submitted']); unset($form_state['storage']); // $form_state['rebuild'] = FALSE; $form_state['saved']= $form_state['values]; $form_state['redirect'] = array ( // double redirect 'mymodule/intermediate_form', 'mymodule/this_form/' . $form_build_id ); }
But I don't know if thats sufficient to preserve the interim state of the form, or will it still be deleted from the cache after the interim_submit completes, or ...(barking up wrong tree)?
thanks Doug -- [ Drupal support list | http://lists.drupal.org/ ]
Definitely the multistep form approach is right on for this. Everything you describe is accomplished by setting form_state['storage']. There are no redirects to sub forms which require posting back to the main one. You simply build the form over and over with different elements depending on values in form_state['storage']. Storage persists throughout the life of the form.
There are several howtos out there. Google is your friend. However, ctools provides an api for building multistep forms, and ahah helper module provides away for doing it with ajax goodness.
On 11/22/2010 07:19 PM, Carl Wiedemann wrote:
This message might be better for the development list rather than the support list.
Would crafting the entire form as a single multi-step work for you? Consider this example: http://www.benjeavons.com/multi-step-forms-drupal-6-using-variable-functions
On Mon, Nov 22, 2010 at 4:31 PM, Doug <doug.duboulay@gmail.com mailto:doug.duboulay@gmail.com> wrote:
Writing a D6 module. I'm trying to build a lengthy form, where at some point, towards the bottom of the form, it would be nice to (1) optionally hit an 'incomplete'/branch submit handler, (2) cache the interim curent form state, (3) double redirect to a new form (create submit ) etc (4) bounce back to the original (with second redirect), (5) reload interim state from the cache, (6) amend with new details gleaned from the intermediate/branch form, (7) finally proceed to the "complete" form submit handler of original form Currently I can double redirect to a second form, but on bounce back, all the original details are lost, which is really unintuitive to the user, who thinks they've already filled out that part. I guess I need to do something like this: function mymodule_interim_submit($form, &$form_state) { $form_build_id = $form_state['values]['form_build_id']; unset($form_state['submitted']); unset($form_state['storage']); // $form_state['rebuild'] = FALSE; $form_state['saved']= $form_state['values]; $form_state['redirect'] = array ( // double redirect 'mymodule/intermediate_form', 'mymodule/this_form/' . $form_build_id ); } But I don't know if thats sufficient to preserve the interim state of the form, or will it still be deleted from the cache after the interim_submit completes, or ...(barking up wrong tree)? thanks Doug -- [ Drupal support list | http://lists.drupal.org/ ]
Unfortunately I'm not so sure multistep will fly for this. Its for a module where the two forms in question are in completely separate files devoted to CRUD on quite separate database tables. The branching I need is to go off and create a new entry in one table (samples), then to come back and link to it (and optionally others) in the original (bookings) form.
Probably it would be easier for me to just save the current state as a record, branch and return to it with an edit form (rather than the original create form), since I already have the functionality for edit. I just thought that using drupal's form cache might provide a simpler mechanism, that wouldn't force me to create a record until explicitly initiated by the user with their ultimate "submit" (avoiding creation of potentially spurious bookings).
In my test, setting form_state['storage'] explicitly rebuilds the original form rather than following the redirect to the intermediate form. If I append the form_build_id as an optional arg for the redirect return, then on return, the cache entry exists but there are no attached form_values. Guess it aint gunna fly :-/
Thanks anyway
On Tue, 23 Nov 2010, Christopher M. Jones wrote:
Definitely the multistep form approach is right on for this. Everything you describe is accomplished by setting form_state['storage']. There are no redirects to sub forms which require posting back to the main one. You simply build the form over and over with different elements depending on values in form_state['storage']. Storage persists throughout the life of the form.
There are several howtos out there. Google is your friend. However, ctools provides an api for building multistep forms, and ahah helper module provides away for doing it with ajax goodness.
On 11/22/2010 07:19 PM, Carl Wiedemann wrote:
This message might be better for the development list rather than the support list.
Would crafting the entire form as a single multi-step work for you? Consider this example: http://www.benjeavons.com/multi-step-forms-drupal-6-using-variable-functi ons
On Mon, Nov 22, 2010 at 4:31 PM, Doug <doug.duboulay@gmail.com mailto:doug.duboulay@gmail.com> wrote:
Writing a D6 module. I'm trying to build a lengthy form, where at some point, towards the bottom of the form, it would be nice to (1) optionally hit an 'incomplete'/branch submit handler, (2) cache the interim curent form state, (3) double redirect to a new form (create submit ) etc (4) bounce back to the original (with second redirect), (5) reload interim state from the cache, (6) amend with new details gleaned from the intermediate/branch form, (7) finally proceed to the "complete" form submit handler of original form Currently I can double redirect to a second form, but on bounce back, all the original details are lost, which is really unintuitive to the user, who thinks they've already filled out that part. I guess I need to do something like this: function mymodule_interim_submit($form, &$form_state) { $form_build_id = $form_state['values]['form_build_id']; unset($form_state['submitted']); unset($form_state['storage']); // $form_state['rebuild'] = FALSE; $form_state['saved']= $form_state['values]; $form_state['redirect'] = array ( // double redirect 'mymodule/intermediate_form', 'mymodule/this_form/' . $form_build_id ); } But I don't know if thats sufficient to preserve the interim state of the form, or will it still be deleted from the cache after the interim_submit completes, or ...(barking up wrong tree)? thanks Doug -- [ Drupal support list | http://lists.drupal.org/ ]