[development] confirm_form from submit hook

Ron Parker sysop at scbbs.com
Tue Mar 3 08:36:13 UTC 2009


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 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20090303/952be0d5/attachment.htm 


More information about the development mailing list