confirm_form from submit hook
I submitted this issue here: http://drupal.org/node/387674, but I really need a response. I think this may be a bug, but I can't be sure right now. Need some advice. I have created a form. I want to submit the form values, validate them, then confirm that the user wishes to proceed. I place a drupal_execute('confirmation_form', $form_values) in my submit hook, and in the 'confirmation_form' I execute "confirm_form". But, it doesn't work. I don't get a confirmation form: the code execution cycles through to conformation_form_submit. form() Input values form_validate() validate values form_submit() Now, I want to confirm that the user wants to continue. If I call a form from within this submit hook that executes a confirm_form, the confirm_form() function doesn't work form_confirm() Execute confirm_form() doesn't work. Code example: <?php function og_user_roles_register_submit ( $form , & $form_state ) { global $user ; if ( $user -> uid ) { $regcode = $form_state [ 'values' ][ 'og_user_roles_regcode' ]; $gid = og_user_roles_gid_from_regcode ( $regcode ); if ( $gid > 0 ) { $node = node_load ( $gid ); drupal_execute ( 'og_user_roles_register_confirm' , $form_state , $node , $regcode ); } } else { drupal_access_denied (); } } /** * Form builder; Builds the confirmation form for adding user to group using regcode. * * @ingroup forms * @see og_user_roles_register_confirm_submit() */ function og_user_roles_register_confirm (& $form_state , $node , $regcode ) { $form = array(); $form [ '#node' ] = $node ; $form [ '#regcode' ] = $regcode ; return confirm_form ( $form , t ( 'Are you sure you want to join this group %title?' , array( '%title' => $node -> title )), 'node/' . $node -> nid , t ( 'This action can only be undone by unsubscribing from the group once joined.' ), t ( 'Delete' ), t ( 'Cancel' ), 'og_user_roles_register_confirm' ); } // Confirmation form does NOT display. Code continues to successfully execute // og_user_roles_register_confirm_submit() // // It's like if a form is called from a successful submit, then it's subsequent submit hook is // automatically successful as well. ?> In all the working examples of confirm_form() I've seen in Drupal 6.x, I do not see an example where it is called from a form submit hook. Usually, it is called in some delete function where the key value is passed along in the url. I want to enter values, validate those values, then confirm that the user wishes to proceed. How do I do that using confirm_form() (if that's even possible)? Thanks for any assistance. -ron
Ron Parker wrote:
I submitted this issue here: http://drupal.org/node/387674, but I really need a response. I think this may be a bug, but I can't be sure right now. Need some advice.
I have created a form. I want to submit the form values, validate them, then confirm that the user wishes to proceed. I place a drupal_execute('confirmation_form', $form_values) in my submit hook, and in the 'confirmation_form' I execute "confirm_form". But, it doesn't work. I don't get a confirmation form: the code execution cycles through to conformation_form_submit.
*form()* Input values
* *
*form_validate()* validate values
* *
*form_submit()* Now, I want to confirm that the user wants to continue. If I call a form from within this submit hook that executes a confirm_form, the confirm_form() function doesn't work
* *
*form_confirm()* Execute confirm_form() doesn't work.
Code example:
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.
participants (2)
-
Earl Miles -
Ron Parker