I am hoping someone can help me.

I am using webform for event registrations, and I want people to be able to register multiple people. So instead of being redirected to the confirmation page after each submission, I want to add a second submit button that says "Add Another" or something like that which redirects the user back to the form. Once they are entering the last person, they hit the "Submit and Finish" button and get the confirmation page.

I figured this would be easy to add a new button, and indeed it is easy to add the button, but every time someone clicks the button, it just reloads the page without submitting any data. The only way I can get the second button to submit is if I name it the same as the first one. But then both buttons say the same thing. Which wouldn't be a problem, I was going to get around that by using images for the buttons changed through css. But, now I have no way to know which button was clicked, because when I use view the $form_state['clicked_button']['#id'] in my submit function, it always displays the id of my new button, even when it is not the one being clicked.

So here is what I have, can anyone tell me what I am doing wrong? It seems simple enough, I want 2 submit buttons, but I want 1 to redirect on submission...

function custom_registration_form_alter(&$form, $form_state, $form_id) {

	if($form['#node']->type == 'event' ) {

			$form['actions']['continue'] = array(
				'#type' => 'submit',
				'#value' => t('Continue'),
				'#name' => 'continue',
				);

			$form['#submit'][] = 'custom_registration_submit';
	}

}

function custom_registration_submit($form, &$form_state) {
	if($form_state['clicked_button']['#id'] == 'continue') {
		$form_state['redirect'] = 'node/12';
	}

}

Comments

quicksketch’s picture

Unfortunately you're correct that this problem is a bit difficult to solve. Webform specifically codes quite a bit of information around which button is clicked. Because of Webform's specific form-handling techniques, we can't use button-level submit handlers. When you use button-level submit handlers, the form-level ones are not executed. So you need to manually specify the submit handlers if you've use a button-level one. I think something like this might do the job in your custom submit handler:

function custom_registration_submit($form, &$form_state) {
  $form_state['clicked_button'] = $form['submit'];
  foreach ($form['#submit'] as $submit) {
    $submit($form, $form_state);
  }
  $form_state['redirect'] = 'node/12';
}

This is a pretty crazy hack, but I think it would do the job.

quicksketch’s picture

Status: Active » Closed (fixed)

Closing after lack of activity.