Closed (fixed)
Project:
Webform
Version:
6.x-3.4
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
8 Dec 2010 at 13:49 UTC
Updated:
5 Dec 2011 at 03:23 UTC
Here's the issue I'm facing. I need to have a second submit button on a webform, with a different #value. I added the new submit button using hook_form_alter but now the form isn't submitted, because of that #value of the button.
Is there a way to achieve this functionality?
Comments
Comment #1
manuelBS commentedif you add a button in hook_form_alter with
you could add a validation handler and a submission handler to your form to check for the button. Do this in hook_form_alter, too
so implement the function _my_validation_handler_function and as for your button like
You can do the same using a submit handler with '#submit' in your form, see also http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....
Hope this will help!
Comment #2
quicksketchThe '#value' of your new needs to be the same as the existing Submit button, since webforms may have multiple buttons (Previous, Next, Save as Draft, and Submit). You can change the label of the submit button to whatever you want under the advanced settings at node/x/webform/settings, then the form will submit.
Comment #3
mariusilie commented@manuelBS
I know know how to do this for every normal form, but this doesn't work for webforms. Thanks anyway :)
@quicksketch
I know I can change the label of the submit button in the advanced settings, but what I need is to have an additional submit button that saves the info as the regulat submit button, but also to save some other infos into another table.
Comment #4
mariusilie commentedI guess the problem is on line 1926 in webform.module.
This line:
Should be something like this:
where $additional_submit_op would be an array of values you can set under the Advanced settings of the webform.
Comment #5
quicksketchI'm pretty sure we're not going to add end-user options to the webform configuration that wouldn't have any effect. Any changes that assist the processing of forms should probably be changed as part of the hook_form_alter().
Regarding the existing code, my point was that you can have two submit buttons (one additional one added by hook_form_alter()), but currently the one you add via hook_form_alter() needs to have the same #value as the one that already exists on the page. So if you want yours to say something other than "Submit", you can change that under the advanced settings.
Comment #6
quicksketchClosing after lack of activity. Newer versions of Webform handle the submit button values better, allowing them to be changed through hook_form_alter() if desired.
Comment #7
mikeejt commentedI don't mean to reopen the issue, but I don't want to create a duplicate one. I'm trying to do the same as mariusilie, having 2 separate submit buttons that have the same behavior (saves webform data to the db, and url redirects).
There are two differences between the two buttons:
1) Text (therefore #value) needs to be different for the two buttons
2) URL redirect is different.
The closest I've come to somebody achieving this is found here: http://agileadam.com/webform-multiple-submit-buttons
But they're using jQuery to hack the txt of the button. And it's not doing a URL redirect. The jQuery part I'm fine w/, but I'm not sure on how to approach the URL redirect. In the end, I would prefer to do it the "correct" way in hook_form_alter() and not partly through a jQuery hack.
Can somebody make a recommendation?
Comment #8
mikeejt commentedEdit - forgot to change Status to "active".
Comment #9
mikeejt commentedFor reference, I saw this post: http://drupal.org/node/1332430
And tried the fix recommended quicksketch, but still didn't work.
Comment #10
quicksketchWhat you're trying to accomplish is beyond the scope of Webform's functionality.
As mentioned in the submission guidelines, I don't provide help with custom coding:
Please refer to other resources such as IRC or Drupal StackExchange to ask your questions.