Re: [development] confirm_form from submit hook
Thank you. This helped. What I did was to create my confirm_form function as a menu callback: <?php $items['og/regcode/confirm/%'] = array( 'title' => 'Confirm registration code', 'page callback' => 'drupal_get_form', 'page arguments' => array('og_user_roles_register_confirm'), 'access callback' => 'user_access', 'access arguments' => array('use registration codes'), 'weight' => 10, 'type' => MENU_LOCAL_TASK, ); ?> So, in my submit hook, I do a "drupal_goto" (as opposed to drupal_execute or drupal_get_form) and put the key variable in the argument as part of the url. This works. But, seems to me that it would be much easier to be able to call another form and pass form variables from a submit hook (as I was attempting to do). -ron Earl Miles wrote: Yes, drupal_execute() submits a form. it does not render the form. The idea there is that it happens completely independently. To do what you want to do, you are going to need to cache the values from your first form somewhere (possibly via values on the confirm form) and do your work in the confirm form submit. In addition, you have the problem that there is no communication between FAPI and whatever called drupal_get_form; your submit cannot actually render a form (it returns a value to redirect to, not output) so the only way you can do this without hacking fapi like I did is to set a global variable. You could also install CTools and use the form wizard tool which this is a nice example of, and in fact might make a lovely example of how to do a more complex confirm form than the ones that currently exist.
On Mar 3, 2009, at 11:55 AM, Ron Parker wrote:
Thank you. This helped. What I did was to create my confirm_form function as a menu callback:
So, in my submit hook, I do a "drupal_goto" (as opposed to drupal_execute or drupal_get_form) and put the key variable in the argument as part of the url. This works. But, seems to me that it would be much easier to be able to call another form and pass form variables from a submit hook (as I was attempting to do).
It's also quite possible that you could open a cross site request forgery that way. What you are really asking about is multi-step form. 'Confir'm is not a hook that is automatically recognized in FAPI in the way the _submit and _validate are. There is an example of what you are trying to do in core, in the node module for the page at admin/ content/node, and the batch operations for that page, which provides a confirm form without redirecting the user at all. To see a better example (node is a little long and slightly confusing) you could look at this module file in CVS: http://cvs.drupal.org/viewvc.py/drupal/contributions/sandbox/mikeyp/system_t... This is a short module I wrote that implements functionality similar to what you seem to want. Most importantly, look at the system_table_cleaner() function and it's switching and return of a different form. This was modeled after the core method used in node module. -Mike __________________ Michael Prasuhn 503.488.5433 office 714.356.0168 cell 503.661.7574 home mike@mikeyp.net http://mikeyp.net
participants (2)
-
Michael Prasuhn -
Ron Parker