Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I can confirm that the privatechoice works fine with webform module using hook_form_alter() - eg:
/**
* Implementation of hook_form_alter().
*/
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'webform_client_form_NID') {
$form['submitted']['COMPONENT']['#privatechoice'] = TRUE;
}
}
Remember to change the form_id, and a component name in the code above.
Awesome contribution BTW, It would be nice to see a webform-privatechoice.module for non coders.
I'll give it some thought, because if it's as easy as dropping the module in and enabling it I could see privatechoice being quite popular.
Comment | File | Size | Author |
---|---|---|---|
#2 | privatechoice_webform.tgz | 881 bytes | Christopher Herberte |
Comments
Comment #1
donquixote CreditAttribution: donquixote commentedThanks for the feedback.
I was hoping that the maintainers of webform (that is, quicksketch) would accept the patch at
#282436-50: Multiple Options, Same Value in 'Select' Form Element (+ Protect from Spam Harvesters)
or alternatively, develop a built-in solution that does the same, copying privatechoice.
No reactions yet.
I am sure it would be possible to extend privatechoice with some dedicated form_alter code to change webform from the outside, but I think it would be much easier to have the component-specific logic in webform directly.
What should we do?
Comment #2
Christopher Herberte CreditAttribution: Christopher Herberte commentedI would not rely on webform maintainers to accept the functionality, instead prove the feature's popularity first. Obviously the inclusion of features into webform which are not going to be used is pointless.
I've written a module to do exactly as described above with webform. It adds a checkbox to the component. needs testing but works for me, and i'm using this on a production site as of next week so i hope it does not break.
One issue I found is that private choice does not work with webform checkboxes and radios -- not a big deal for me.
Comment #3
Christopher Herberte CreditAttribution: Christopher Herberte commentedInstructions for the above module:
Note: this only works for webform Select "List Box" component at present.
* Extract and enable module as per standard installation procedures, see http://drupal.org/node/70151 for further information.
* Create new or edit existing webform, go to Webform -> Form Components.
* Add or edit existing "Select options" component. In the "Edit component" form there is now a checkbox for "Enable Private Choice?", tick it, Submit.
* Check HTML source to check the option keys are in fact hidden.
Comment #4
donquixote CreditAttribution: donquixote commentedLooks like a good start.
Should we really make this a new (sub)module, or rather have it enabled by default? Atm I see a higher chance of someone forgetting to enable the privatechoice_webform submodule, than the chance of someone who does not want this extra feature added to webform.
It certainly does improve modularity, though. And it will allow privatechoice_webform to be replaced with something else: A solution built-in with webform, or another module which leverages privatechoice. If admin_menu had that modularity, then dqx_adminmenu would contain less copy-paste.
So, with your approval, I shall include this code as a submodule. And maybe I can make it work for checkboxen and radios, too.
Comment #5
Christopher Herberte CreditAttribution: Christopher Herberte commentedAwesome, go for it. I'm looking forward to seeing privatechoice_webform in a future release.
Comment #6
donquixote CreditAttribution: donquixote commentedStorage: Would we gain anything from storing this stuff in the webform_component table, instead of a custom variable?
The only real benefit I can imagine at this moment is if there are large numbers of webform nodes, then we can avoid loading their settings all at once. But that is not very likely.
Note: Serialized array in the 'extra' column.
Comment #7
Christopher Herberte CreditAttribution: Christopher Herberte commentedextra column would be a better place for it. i see also webform_component_insert hook in webform.components.inc - if that's the right place to start. will take a look later
Comment #8
donquixote CreditAttribution: donquixote commentedJust sent a contact form message to quicksketch.
Would be nice, if we get some feedback.
And yeah, there might be some hidden treasure in the webform api!
Comment #9
dooug CreditAttribution: dooug commentedwebform 6.x-3.11
privatechoice 6.x-dev
The private choice wasn't working for me when I set the
#privatechoice
toTRUE
. I investigated a bit, and saw the process & element_validate functions weren't being added to the element, so I did it in my hook_form_alter (below). I believe those two lines shouldn't be necessary for me, but it was the only way I could get it to work.For some reason the privatechoice module's process & element validate functions were only being added/called on the date & time elements on my webform (and not my other select option elements). I tried playing with the module weights in the system table but that didn't seem to do it.
Comment #10
donquixote CreditAttribution: donquixote commentedWhat is the element type of the $form['submitted']['number_of_attendees'] ?
The #process and #element_validate should be set in function privatechoice_elements() - can you check what is going wrong there?
Comment #11
dooug CreditAttribution: dooug commentedIt seems
privatechoice_elements()
worked, but only altered the #process and #element_validate for my date/time select options, but not the other select option elements.the form element
#type
is radiosComment #12
donquixote CreditAttribution: donquixote commentedStrange.
Could you check if some other module is overwriting the #process and #element_validate?
Not sure where you would have to look..
Or maybe that's a matter of module weight?
Comment #13
dooug CreditAttribution: dooug commentedYeah, I tried to figure out if any other modules were altering the form or if the modules' weight were causing them to fire out of order. It is likely some other module is causing this, I just thought I'd share my temporary solution. Hopefully, I'll find time to figure it out soon.
Comment #14
donquixote CreditAttribution: donquixote commentedYou could visit
yoursite.com/devel/elements
this will give you some useful information :)
(if you have devel enabled)
Comment #15
dooug CreditAttribution: dooug commentedthanks for the suggestion, it looks like the privatechoice #process & #element_validate functions are there for
radios
Now that I think about it, I suspect my issue is caused by my webform module being a bit out of date. It looks like this like in webform/components/select.inc resets those functions (instead of appending them into the array). Although, I am perplexed because the webform module weight is -1, so it shouldn't happen after private choice.
$element['#process'] = array('expand_radios', 'webform_expand_select_ids');
Comment #16
donquixote CreditAttribution: donquixote commentedThe modifications from hook_elements(), which privatechoice uses, are applied before any hook_form_alter().
Comment #17
dooug CreditAttribution: dooug commentedI updated to webform 6.x-3.14.
It seems line 366 in
webform/components/select.inc
sets the#process
functions for the radios element. If I comment out that line, privatechoice works (but those process functions from webform obviously don't work). I haven't figure out what prevents all of these process functions (from webform and privatechoice) from being called.----UPDATE: -----
I made a tweak to
webform/components/select.inc
. It appears the webform renders the element but doesn't use the#process
functions that have already been set by anyhook_elements
. I am unsure my patch is the correct way to do this....I found this issue was already pointed out in the Webform issue queue: http://drupal.org/node/1188774#comment-5219542
So, the problem is in webform not privatechoice. Thanks for the help, hopefully the webform module maintainer fixes this issue soon.