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 confirmation_form I execute "confirm_form". But, it doesn't work. I don't get a confirmation form.
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:
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.
So, everyone says confirm_form, but I have yet to see how it works in an example other than deleting something. See all the examples here: http://api.drupal.org/api/function/confirm_form/6
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)?
Comments
I did get this to work in a fasion, but...
What I did to get this to work was to put the confirm_form into a function that is called 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 the form variables from the submit hook (as I was attempting to do).
The reason I labled it as a bug was because neither drupal_execute nor drupal_get_form (which is suppose to render the form) worked. To me, it seems like I should be able to take the form values that I just validated, and send them to another form for further confirmation.
Here's what I mean:
The form in question is og_user_roles_register_confirmRight now, what works is to do a drupal goto from the submit hook:
What I believe I should be able to do (but cannot) is do a drupal_get_form (which should render the confirm_form) and pass the form values that I have already validated to a confirmation screen:
Shouldn't the latter work as well? If not, why?
I' am in the same situation.
I' am in the same situation. The confirm form doesnt appear on the screen and it goes on normally, why does it happen?? why doesn't it show the form??
If anybody could help or post any code which runs properly, I would really appreciate that.
Thanks!!
Subscribe, trying to do the
Subscribe, trying to do the same thing, but confirm form dosn't seem to do what I need.
A late answer
I am no expert at this, but during my research of the conirm_form function, I realized that it return just another piece of the $form array. It doesn't return to the page. The rest of your _submit handler does this, so in order to get back you would need to alter the $form_state['rebuild'] key to TRUE.
So that should do it. The only other problem I see is that you need to have your confirmation function set a hidden form element that let's the next pass through the submit handler know that the form should be processed and the )submit function returns TRUE.
This is a pretty nice example of this code:
Display a confirmation message before processing a form
Hope that helps
The URL in stevenator's
The URL in stevenator's comment above should go to Display a confirmation message before processing a form.