Users have long requested the ability to dynamically populate a select list in Webform (see http://drupal.org/node/151603; there are several other issues in the Webform issue queue about this). This would allow users to create select lists populated with, for example, upcoming events. @Bartezz created a patch to Webform 2.x that modified the Webform core module, and provided a new Dynamic Select component. This patch was never committed to the 2.x branch as the maintainer of the project created an API for Webform 3.x that allows third-party components in Webform (http://drupal.org/node/525446). Webform's maintainer @quicksketch has indicated that @Bartezz's patch will not be committed to 2.x branch as development has ceased on Webform 2.x.
Myself and @gloryfish updated the code written by @Bartezz to utilize the Webform 3.x API. Our module provides a new component, Dynamic Select, to Webform 3.x. The "Options" field in the Dynamic Select component allows a user to populate the select list via PHP code. The code must return an associative array; the values in the array are what will be saved in the Webform results table.
An example is provided in the README of how to populate the select list with a View, which will likely be the most popular use case for this module.
@gloryfish (http://drupal.org/user/281675) and @Bartezz (http://drupal.org/user/284019) will also be applying for CVS accounts to co-maintain this module.
Please let me know if you have any questions.
Thanks!
Kosta
Comment | File | Size | Author |
---|---|---|---|
#7 | dynamicselect.tar_.gz | 6.04 KB | kostajh |
#1 | dynamic_select.tar_.gz | 6.05 KB | kostajh |
Comments
Comment #1
kostajh CreditAttribution: kostajh commentedComment #2
GloryFish CreditAttribution: GloryFish commentedI would like to be a co-maintainer of this module.
Comment #3
Bartezz CreditAttribution: Bartezz commentedI would like to be a co-maintainer of this module.
Comment #4
apadernoHello, and thanks for applying for a CVS account. I am adding the review tags, and some volunteers will review your code, pointing out what needs to be changed.
As per http://drupal.org/cvs-application/requirements, the motivation message should be expanded to contain more details about the features of the proposed module, and it should include also a comparison with the existing solutions.
As you are referring to an existing project, why didn't you open a feature request for the existing project?
CVS applications are for single users.
Comment #5
kostajh CreditAttribution: kostajh commentedHi Kiam,
Thanks for the reply.
As per http://drupal.org/cvs-application/requirements, the motivation message should be expanded to contain more details about the features of the proposed module
The module has one feature: it provides a new component, Dynamic Select, to the Webform 3.x module. To use it, you enable the Dynamic Select module. Create a Webform or edit the Webform to which you wish to add a dynamic select component. Under "Type" you should now see a component called "Dynamic Select". Enter a component name and click "Add". All fields are similar to what you are provided with in the other Webform component options. The exception is the "Options" field. You can enter PHP code in this field. Your code must return an associative array; the values in the array are what will be saved in the Webform results table. In all other respects, the component works like the regular Webform Select component. Administrators will have to be wise about how they grant permissions for users to create/edit Webforms if they are using the Dynamic Select module; I have made this clear in the README.
and it should include also a comparison with the existing solutions.
There is no existing solution. There is however a lot of demand for this functionality. As noted in the original motivation message, Webform has been updated in 3.x to provide an API for other modules to provide components. This module does just that.
As you are referring to an existing project, why didn't you open a feature request for the existing project?
I requested this to be included in the Webform 2.x branch, but the maintainer had good reasons to not want to include this since development is focused on Webform 3.x. To quote the maintainer of Webform: "the module provided in this issue will never be part of the Webform project itself." #151603: Can I put options in a select field from a database query? The Webform 3.x API was created for the specific purpose of allowing developers to extend Webform's components via modules, rather than adding feature requests to the core Webform module. Hence this module, rather than a patch Webform 3.x, which would not be approved for "by design" reasons.
CVS applications are for single users.
I understand that, but if the application is approved, I would like to add @gloryfish and @bartezz as co-maintainers.
Thanks for your help.
Comment #6
apadernoIf they don't apply for a CVS account, they cannot get one. They should wait your CVS account is approved, and then apply for one. It is not possible to get a CVS account if not following the steps you followed; that is the only way for the tab user/<nid>/edit/cvs to appear, which is the one that allow to approve a CVS account, or disable it.
Comment #7
kostajh CreditAttribution: kostajh commentedPer the recommendation in Pro Drupal Development ('Development Best Practices'), I removed the underscore from the module name. Updated code is attached.
I look forward to the code review. Thanks!
Comment #8
luthien CreditAttribution: luthien commentedHello, I installed the dynamic select module in our production site and it is working perfectly fine. I used the module to populate a drop down select with content generated by querying an external database. I'm surprise this module is not part of the core of the webforms module. For users like me, that need to combine Drupal forms with external databases fields, it is a very important module to have.
Comment #9
quicksketchSince I've removed all custom PHP functionality from Webform itself (this stuff is dangerous folks), if kostajh wants to maintain http://drupal.org/project/webform_php as well once his application is approved, that would be fine by me.
Comment #10
apadernoThank you, quicksketch, for chiming in. Let's see what kostajh replies.
Comment #11
kostajh CreditAttribution: kostajh commentedHi quicksketch & kiam,
In the original issue #151603: Can I put options in a select field from a database query? that prompted the development of this module, quicksketch suggested yesterday that instead of a new module I consider extending webform_php to achieve the functionality that exists in the Dynamic Select module.
My inclination is to not proceed with that route for the following reasons:
Those are my thoughts. Let me know if you have any more questions. Also, quicksketch feel free to contact me via my contact form if you'd like to discuss further outside of the issue queue, and thanks for contributing your thoughts.
Comment #12
quicksketchThere are two kinds of people that make Drupal sites: Those that type code into textareas and those that don't. Since I'm of the latter group I don't really care how this ends up happening, I'll let those other people install Contemplate, PHP filter, CSS Injector, Dynamic Select, Webform PHP, and whatever other unholy modules they want to install (might as well throw in Hooker).
It's true the two modules accomplish different things, it's just likely that a user of one would also be a user of the other. They both add PHP textareas to Webform, just in different places, making the grouping of them seem like a logical thing to do.
Comment #13
GloryFish CreditAttribution: GloryFish commented@quicksketch I am also of the latter group. The concept of executing arbitrary user-supplied code within the same context as trusted code is contrary to all good sense. it is, as you say, unholy.
That being said, PHP execution isn't going away. There ARE (shudder) people who use it. Likewise, there are people now who want to populate a webform select programmatically. This module provides that functionality. Adding the functionality to webform_php might be a great idea but it hasn't been done yet.
I'm new to this aspect of Drupal but wouldn't it make sense to make this module available now, rather than waiting for a whole new chunk of functionality to be developed? Or, put another way, which is more important: providing all potentially-related functionality in a single module, or getting functionality that works into users hands in a timely fashion?
If at some future time someone extends webform_php to handle selects then this module would most likely be deprecated, but right now that isn't the case.
Comment #14
quicksketchWell I shrug. I think putting in webform_php would be the "right" way. This approach from the start is dubious (duplicating 90% code of an existing Webform component). But again, I don't really care how this happens so long as it doesn't cause more support requests in the Webform queue. Maybe I was just looking for someone to maintain webform_php, because I sure don't want to. :P
Comment #15
luthien CreditAttribution: luthien commentedconsidering I'm one of those users that needs to populate fields from custom PHP code, what will be the correct way of populating a hidden text field with custom code? I'm using the dynamic select already to populate the select box, now I need a few hidden fields with values coming from an external database. I don't need to validate fields, just to use the hidden fields to build the confirmation emails. I also need the "add another" textfield functionality but that one is not as important as populating fields with custom code. Thanks.
Comment #16
Bartezz CreditAttribution: Bartezz commentedWell I suppose you could use dynamic select as your hidden field... just have one option and hide it via css... not the best solution but one you could implement right now untill better solutions are available...
Add another is a bigger issue... and one that doesn't belong here. Have a look here: http://drupal.org/user/284019
Cheers,
Bartezz
Comment #17
GloryFish CreditAttribution: GloryFish commentedIt would be useful to keep discussion in this (3 week old) thread limited to whether or not kostajh's cvs account request will be approved. Is there anything we can be doing to help with that decision?
Comment #18
luthien CreditAttribution: luthien commentedHi Bartezz, the solution you proposed is the one I was using because the dynamic select was the only available tool to achieve my goals. As I mentioned in a previous post, the dynamic select module is working and it is working fine, so count my vote towards the approval of kostajh's request please.
Comment #19
roball CreditAttribution: roball commentedIf the suggested module will be approved and depends on webform.module, I suggest to rename it to "webform_dynamicselect" or another name starting with "webform_".
Comment #20
kostajh CreditAttribution: kostajh commented@roball - I agree.
Kiam, is there anything else you need from me for the code to be reviewed?
Comment #21
roball CreditAttribution: roball commentedJust gave it a try. Some remarks:
Comment #22
luthien CreditAttribution: luthien commentedHello kostajh, I started a new topic and it is related with your module and webform. Could you please look at the post? perhaps you know the answer. Thanks.
http://drupal.org/node/769302#comment-2838324
I also noticed that values selected using the dynamic select are not being displayed in the web form reports (webform-results/table). The field is empty for the report.
Comment #23
apadernoComment #24
Bartezz CreditAttribution: Bartezz commentedWon't fix? So no CVS account for kostajh?
Cheers
Comment #25
apadernoIf kostajh wants a CVS account, he can re-apply to get one.
Comment #26
vasanthkay CreditAttribution: vasanthkay commentedThe dynamic select module created by kostajh is very useful... I used it in one of the form I created.
As luthien had pointed out above there is an issue wrt report generated from the webform. The dynamic select field is empty in it.
Also, I noticed one more issue wherein, doing validations for the dynamic select field with "webform validation" module is not possible. It does not detect the dynamic select option as one of the fields in the form.
Has anyone experienced the same problems ? Any ideas or alternate solutions to overcome these two problems would be highly helpful to me and the community as well.
Comment #27
kostajh CreditAttribution: kostajh commented@vasanthkay: check out hook_webform_select_options() in the webform_hooks.php file in Webform 3.x.
Comment #28
vasanthkay CreditAttribution: vasanthkay commented@kostajh
I see that hook_webform_select_options_info() has implemented a pre-defined list for days of the week and whose values are hardcoded in the webform.options.inc file.
There is one more pre-defined list which creates a list of countries.
I had used your #7 module and entered a query in it to dynamically load values from database and present it in the form.
So, in order for these values to appear in the report, could you give me some more pointers ?
I see that webform_get_submission() in webform.submission.inc retrieves the submission data and webform_results_download in webform.report.in creates the report.
I am not sure if I misunderstood what you had mentioned in the previous reply. I am quite new to Drupal and hooks implementations. Could you please help me out with some more pointers.
Comment #29
luthien CreditAttribution: luthien commenteddue to the problem with the reports, for one of the dynamic web forms, I started using the http://drupal.org/project/webform_report module to generate the reports. It worked out well as I was able to generate the reports and I added some filters too.
Comment #30
vasanthkay CreditAttribution: vasanthkay commented@luthien
Thank you so much luthien and kostajh. As suggested, I used "webform report" module. Now, the reports are generated correctly with the dynamic select values included in the excel rows.
There is still one more challenge which I am facing,
The dynamicselect option is not listed by the "Webform Validation" module and hence I am not able to validate the selections done by the users.
The form which I am implementing right now, would be complete if I am done with this last part.
Could you share with me your ideas/suggestion regarding how this can be implemented ? or has any of you implemented this in some other way other than editing code in "Webform validation" module. ?
Comment #31
vasanthkay CreditAttribution: vasanthkay commented@kostajh, luthien
I found that it is possible to validate the dynamic select options using "Webform validation" module, by including "dynamicselect" in the code wherever it checks for component types to validate and then using one of the validation rules.
By editing this code I was able to get it almost working. However there is still one small issue, which I would like to discuss with you. In a conventional select field, the default select box displays a test "- Select -" in the select box below which all the other options for selection are present.
The validation rules does not validate for this text ( - Select - ) as one of options. It just checks if any of the options have been selected in case its a mandatory field.
Whereas in a dynamic select option, there is no (" - Select - ") default option.
Hence, it display one of the dynamic options by itself as a default value. Hence, all the values in the drop down box EXCEPT this 1st value gets validated.
Is there a way by which the default ("-select-") field can be added to every dynamic select box ?
By adding this all the values in the dynamic select box gets validated and it completes the functionality too.
Comment #32
roball CreditAttribution: roball commentedIt seems that the Webform View Reference Component module is doing exactly what the proposed module here is supposed to do.
Comment #33
luthien CreditAttribution: luthien commentedcheck out the above module, it might works for what you need. I used the hook_webform_select_options() to create my dynamic drop down fields and I'm not doing validation because I don't needed for this particular field.
See example below:
what I would like to do is to display another dynamic drop down box based on the selection of the first dynamic drop down box. The validation will be done based on the first selected value. If you get it to work please let me know. In my particular case, the drop down boxes changes based on dates calculated from today's date. It is kind of volatile-dynamic boxes as the values are never the same.
Comment #34
apadernoPlease read the following links as this is very important information about CVS applications.
Drupal.org has moved from CVS to Git! This is a very significant change for the Drupal community and for these applications. Please read Migrating from CVS Applications to (Git) Full Project Applications and Applying for permission to opt into security advisory coverage on how this affects and benefits you and the application process. In short, every user has now the permissions necessary to create new projects, but they need to apply for opt into security advisory coverage. Without applying, the projects will have a warning on projects that says:
Comment #35
apaderno