Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hi,
Is it possible to write php code in the options field to automatically and dynamically populate
the list of options from a table in the database?
If it`s not possible, could you point me to another way of doing it?
What I want is that the different options will be the recent story posts on my site.
Thanks
Comment | File | Size | Author |
---|---|---|---|
#83 | dynamic_select_6.x-2.x.zip | 4.17 KB | Bartezz |
#83 | webform_load_webform_components_6.x-2.9.patch | 2.51 KB | Bartezz |
#70 | webform_load_webform_components_6.x-2.8.patch | 2.51 KB | Bartezz |
#69 | webform_load_webform_components-6.x-2.8.patch | 2.26 KB | Bartezz |
#59 | webform_load_webform_components.patch | 2.49 KB | Bartezz |
Comments
Comment #1
RoloDMonkey CreditAttribution: RoloDMonkey commentedI need exactly the same thing. I have succeeded in adding the fields dynamically using hook_form_alter(). Unfortunately, I haven't been able to get Webform to accurately reproduce the dynamically generated content in the email or the submission view.
I'm very close. If anyone has other pieces to this puzzle I think we can make this work. Maybe even create a new component?
Comment #2
RoloDMonkey CreditAttribution: RoloDMonkey commentedOkay, I have found several other requests for this. I have pointed them all at this thread and closed them as duplicates. I will finish a preliminary hack for this soon.
Comment #3
RoloDMonkey CreditAttribution: RoloDMonkey commentedComment #4
RoloDMonkey CreditAttribution: RoloDMonkey commentedI have finished a very preliminary hack. I have started documenting what I did, and I am providing the source code that I have developed so far. You can find all of this at:
http://www.irolo.net/drupal_webform_and_dynamic_checkboxes
I hope to polish this over the next few days.
Comment #5
wonder95 CreditAttribution: wonder95 commentedWhat about the Active Select module?
Comment #6
RoloDMonkey CreditAttribution: RoloDMonkey commentedI'm not sure that Active Select does what we need. Not only do you have to generate the selection dynamically, but you also have to save a submitted value to the database and retrieve it later.
Comment #7
RoloDMonkey CreditAttribution: RoloDMonkey commentedI have finished the final version of my dynamicselect component. Documentation and the file are available at:
http://www.irolo.net/drupal_webform_and_dynamic_checkboxes
In addition, a demonstration will be available for a while at my staging site:
http://immaculata.bydesign-area51.com/registration
At this point I think that I have provided enough of a framework for a developer to solve similar problems. I would like to encourage others to expand on what I have done, but I am closing this particular issue for now.
Comment #8
blairski CreditAttribution: blairski commentedHi RoloDMonkey ,
Thanks for your tutorial and code. I have used it and ammended it to prepopulate the webform with data from the user profile table. That all works fine. However, I am having trouble getting the default value to set. Its probably really simple. I know this issue is closed, but I am not sure where else to post. Can I post my alterations here for someone to have a quick look?
Comment #9
Summit CreditAttribution: Summit commentedHi,
I set this item to active if you don't mind, I was wondering what the status of this component is after release 1.8?
Will your dynamicselect component be part of webform components in this great module?
This way it will be possible to follow up webform development more quicker, right?
Thanks for your consideration already!
greetings,
Martijn
Comment #10
RoloDMonkey CreditAttribution: RoloDMonkey commentedMartijn,
The dynamicselect component that I created was only to meet my needs. I documented what I did so that other developers could create similar solutions.
I do not currently have any plans to turn the dynamicselect into a "real" webform component. I would love to see someone else build on what I did, but I simply do not have the time.
If you need a particular solution but you are not able to write it yourself, you can try the companies that provide Drupal Services or you can get bids from the Paid Drupal services forum.
Comment #11
RoloDMonkey CreditAttribution: RoloDMonkey commentedblairski,
Please post your code as an attached file and I will see if it is something easy to figure out.
Comment #12
quicksketchI'd certainly be up for including this as part of webform, though I'd like to wrap it into the existing select element as either a separate field or just a checkbox for "Use PHP to generate options" to reuse the existing textarea.
Comment #13
dolittle CreditAttribution: dolittle commentedWhen are you planning to implement this functionality?
I've tried webform 2.x but couldn't find it.
Thanks
Comment #14
quicksketchYes, I've got a lot on my plate but I hope to get to this soon.
Comment #15
blairski CreditAttribution: blairski commentedRoloDMonkey,
Sorry it has take me a while to attach the file. I changed you function _dynamicselect_load_options() to bring in one of the user profile fields (counties). That works fine. I am just getting stuck on setting the default, which should be the users current county that they set in their profile.
Comment #16
dolittle CreditAttribution: dolittle commentedThere is a beta1 release of webform 2.0.
Will the 2.0 version support this feature?
Please...
Comment #17
quicksketchNo, the first release of 2.0 will not support this feature. I'm very busy with a lot of things.
Again, patches to add the feature would gladly be accepted as long as they are well-written and included in the current select.inc rather than as a another select list. This feature will only be included in the 2.x version as I'm trying to depreciate the 1.x version.
Comment #18
quicksketchMarked http://drupal.org/node/242644 as duplicate.
Comment #19
gordonbooker CreditAttribution: gordonbooker commentedI have downloaded the dynamicselect.zip file and looked at the code. Unfortunately, as a newbie it's beyond me as to how to make this work, or to make it into a patch.
It would be extremely useful if anyone could give some advice as to how to use this code.
Comment #20
Oghnia CreditAttribution: Oghnia commentedI can't get this patch to work... any help guys
Comment #21
Oghnia CreditAttribution: Oghnia commentedok a little update,,
this works,, but for some reason the I can't get the selected fields to display into the submitted email..
I get all other fields but this one,,
is something missing?
Comment #22
quicksketchMarked #254169: Using hook_form_alter to change options. as duplicate.
Comment #23
ehowland CreditAttribution: ehowland commentedHere is a patch for select.inc that was made against 5.x-2.0. It adds a php fieldset which contains a boxes for adding php code that creates defaults and for options. In order to see the (collapsed) fieldset the user must have "use PHP for additional processing" permissions.
This patch also makes the Options box optional (since the php generated data overwrites anything in that field) but adds some error checking to make sure that there are either options or php.
Several weeks ago I looked at the differences between 5 and 6 and it looked to me like it might well apply cleanly against 6 but I have not tested it.
Comment #24
ehowland CreditAttribution: ehowland commentedUMM. It seems that the nesting caused an error message to show up when it should not have (claiming no data). A slightly better patch.
Comment #25
quicksketchThanks for the patch whiteowl!
The approach in this patch seems a bit strange. Rather than evaluating the PHP when showing the form, you're evaluating when creating it. This makes it so that the select list can't contain truly dynamic values, you basically just saving a little bit of work when setting up the form initially.
This patch should be made to work on display, rather than inserting values and then letting Webform use those options as it did before.
Comment #26
ehowland CreditAttribution: ehowland commentedI agree that this is strange but I believe that it is not strange how you think it is strange.
Try adding this as the php Options:
return array('c'=>date('c'), 'r'=>date('r'), 'U'=>date('U'));
Off topic here, but I get an error message (which I do not see the source of) about illegal choices if I do not make these associative arrays. Although the error message is different ("An illegal choice has been detected. Please contact the site administrator.") I thought it might be some sort of problem with the special characters, but I do not understand why date('U'), which is just a number, does not work. The patch only evaluates the PHP one time, but I wonder if the function is called several times and the discrepancy of the choices between these calls triggers an error which in turn generates the error message.
When you refresh the form each of these dates updates every time (at least for me).
Every time you generate the form you will see the values from the last invocation of the form in the Options box. This is because (and this is the slightly odd thing) every time the form is generated, the newly generated values are stuffed back in the database so that when the form is processed the data shows up as valid data. Without this step the data does not get entered into permanent storage. This is what you helped me with before in the issue http://drupal.org/node/254169. So the form administrator sees the historical data but the users do not!
So the summary is - yes some strangeness - no it works how you want (I think).
Comment #27
ehowland CreditAttribution: ehowland commentedOne other thing I did not notice before is that this makes the reporting modules a bit wierd.
I am mostly interested in the table output and that works fine both for both my interest and for the dates (at least as associative arrays which renders the results to be unchanging - not the most useful case).
The odd behavior comes if you go to the results tab and click the view screen for a transaction. A new form is generated from the data, and that new form will have the current date (from the PHP) rather than the original date. This is OK if you are having your users pick a date format, but not if you wanted them to pick a specific time (One week from now, Two weeks from now, Never). This will not be specific to this date example, but to any changing data (sort of the point for using PHP in the first place). This is a wider issue and its solution will require more restructuring beyond the select.inc file.
Comment #28
coupet CreditAttribution: coupet commentedsubscribe
Comment #29
Duncan Pierce CreditAttribution: Duncan Pierce commentedsubscribe
Comment #30
jazzitup CreditAttribution: jazzitup commentedsubscribe
Ok, I've seen a patch of a patch by whiteowl in #24.
Is it the full patch for the original select.inc, since there is no attached patch in #23?
Comment #31
ehowland CreditAttribution: ehowland commentedThe full patch is in 24 as an update to the patch that as previously in 23.
Comment #32
jazzitup CreditAttribution: jazzitup commentedThere is no patch in #23 and those "-" and "+" signs at the beginning of the lines just don't make sense if I apply #24 on the original select.inc file (I'm using webform 5.x-2.1.1). I've just reversed the logic: all "-" became "+" and now it works, but the result is not so stable.
Comment #33
Summit CreditAttribution: Summit commentedHi Madjoe, Could you file your patch please?
Thanks a lot in advance,
greetings,
Martijn
Comment #34
jazzitup CreditAttribution: jazzitup commentedSince I don't know which version of webform do you use, here's the entire select.inc in the archive for 5.x-2.1.
It still have some weird bugs and it's not that stable so this code really does need work, and I'm playing with it right now.
@whiteowl: Is it possible that this does not work as select options with this PHP addition to a select component:
I've checked the same PHP code on page.tpl.php and I can see the array elements by doing print_r ($f); but I have problems with creating options for my select box by using this method.
Could you please check my select.inc... did I miss something with your patch?
If I try to Submit this custom PHP code while creating a new select component, and go to see the form, I could only see "select..." option with no other options inside of my "php select box", and if I refresh the same page, I can't see that select box anymore - it just vanishes somehow. Maybe we should escape double quotes before storing custom PHP code like this to the database?
Comment #35
jazzitup CreditAttribution: jazzitup commentedI've created a function func() in my template.php that returns array("A", "B", "C").
If I create a select component, this is what is stored in the database within extra field:
After I visit the form for the first time, I could only see "select..." as an option in a select component.
After my visit to the form this is the content of the same extra field, but the select component is not visible in my future page visits:
Take a look at the prefix "pre_" that is the default prefix for my database tables?! The regular "Default value" becomes "pre_".
Comment #36
lelizondo CreditAttribution: lelizondo commentedsubscribe
Comment #37
EdCazini CreditAttribution: EdCazini commentedsubscribing
Comment #38
marcvangend-subscribe-
Comment #39
quicksketchTo re-iterate, the approach in this patch is incorrect and need to be rewritten before it is included in the final project. Instead of pulling in the options when configuring the element, the options should be pulled in when displaying the element (or viewing results). This patch needs to be fixed before it's included in Webform.
Comment #40
gterez CreditAttribution: gterez commentedsubscribing
Comment #41
Rick Hood CreditAttribution: Rick Hood commentedI am probably way off here, but:
You can put a token in the options field. I have experimented where I put %get[model] in the options field, which will show "blah-blah" as the (one) select option if URL to the form is /mywebform?model=blah-blah.
I know nothing about "token creation" but would there be a way to create a token whose value contains the result of a query to the database that brings back the stuff you want to show here? Then you could just put that token in the options field?
BTW this is all for Webform 6.x-2.3
I tried RoloDMonkey's method above but am lost because things have change so much from 5.x to 6.x-2
Comment #42
ngmaloney CreditAttribution: ngmaloney commentedI put together a 5.x module for dynamic selects. None of the other patches fit the bill for what I needed. It renders the options at display time. I'll gladly port it to 6.x if there is any interest. I currently have the module hosted at http://github.com/ngmaloney/dynamic_select/tree/master
Comment #43
Rick Hood CreditAttribution: Rick Hood commentedWow that's great. I would greatly appreciate a port to 6 when you get a chance. I am working on a D6 project now that needs this.
Comment #44
Christopher Herberte CreditAttribution: Christopher Herberte commented+1 D6, subscribing
Comment #45
hbevan CreditAttribution: hbevan commented+1 for D6!
Comment #46
millenniumtreeD6 pls
Need it for emails of all employees in company and don't want to show email addresses on the site (neither displayed nor HTML code)
Comment #47
Rick Hood CreditAttribution: Rick Hood commentedI'm kind of desparate to get a dynamically created list of checkbox choices on a webform for a project I am working on (D6 and Webform 6.x-2.3). Wondering if there is some other option. Could I add the check boxes via hook_form_alter with a dbquery in there someplace or would that not work?
In a post above I was also wondering if somehow a token could be created (not sure how to create tokens) that could be put as default for this field.
If all else fails I guess I could forget abotu using webform for this particular form, create a content type for it instead and use messaging to email it.
Any direction anyone can give me would be appreciated. ;-)
Comment #48
John Pitcairn CreditAttribution: John Pitcairn commentedHere's an alternate rather crude solution that should work:
Create a markup field as your first field. In there, run whatever you need to generate your array of values (recipient names perhaps) for the form select. For each of those values, create and populate a custom session variable. You might want to use an array that uses some other related value (recipient's email address) as a key, so you can do a lookup later to extract that. Store that array in another session variable (or perhaps a global if you can get that to work). ie:
for($i = 0; $i < count($myvalues); $i++) {
$_SESSION['my_webform_var_'.$i] = $myvalues[$i];
}
$_SESSION['my_webform_vars_lookup'] = array_flip($myvalues);
In the webform select field, hand-populate the select entries with your session variables. You'll need to decide on some maximum number:
%session[my_webform_var_0]
%session[my_webform_var_1]
etc
Note you can't have separate value/display here using this syntax, so just make it the display version.
In the webform advanced settings "additional processing" field, grab the user-selected value, translate that into whatever you need the real value to be (like an email address - here's where that reverse-lookup array comes in handy), and place that wherever it needs to go. Finally, unset all your custom session variables.
Comments?
Comment #49
jphelan CreditAttribution: jphelan commented+1 for D6
Comment #50
bignab CreditAttribution: bignab commentedHere is a 6.x port of the module you put together. I borrowed some of the code from the regular select box in order to email and display the multiple values.
Comment #51
csc4 CreditAttribution: csc4 commentedSubscribing
Comment #52
ngmaloney CreditAttribution: ngmaloney commentedbignab: Great work!
Comment #53
jwhat CreditAttribution: jwhat commenteddynamic_select worked for me in D6 to query a Taxonomy vocab and display it in it's proper hierarchical view.
Here's the code I used in the "options" setting for this form component:
Comment #54
Summit CreditAttribution: Summit commentedHi, Where do you put this code from #53 in webform please?
thanks for your reply in advance,
greetings, Martijn
Comment #55
EdCazini CreditAttribution: EdCazini commentedIf you have not already created one, add a new form component of type select, or edit an existing one. Either ways, while creating or editing that select component, there is an Options textarea there, copy and paste the code from #53 above.
Comment #56
Syph CreditAttribution: Syph commentedI get an error stating
Options within the select list must be unique. The following keys have been used multiple times:
* }
Comment #57
Bartezz CreditAttribution: Bartezz commentedsame problem here, subscribing!
Comment #58
Bartezz CreditAttribution: Bartezz commentedBignab and others who got this working,
How should one install this D6 version of dynamic_select?
I've added it to sites/all/modules and enabled the module but it doesn't work.
Do I have to patch my 6.x-2.7 version of webform module like needed when using the 5.x version of dynamic_select?
When I look at the code I see it uses a hook which isn't even available in 6.x-2.7 version of webform.
Please tell me how to get this working!!!
Bartezz
@ quicksketch; will this get into 6.x-3.x? It's a neat feature!
Comment #59
Bartezz CreditAttribution: Bartezz commentedOk, I've got it working with the code supplied by bignab in #50 and the patch for D5 inserted by hand in the 6.x-2.7 version of webform.module.
To install Dynamic_select for D6;
- download http://drupal.org/files/issues/dynamic_select_6.zip
- unzip to sites/all/modules
- enable the module in admin/build/modules/list
- donwload the attached patch for webform.module 6.x-2.7
- apply the patch
- then in node/[nid]/edit/components you will find you can add a component of the type dynamic_select
- add one and within the settings for this component you can add php under 'options'
Sample code from strikeink, to list the terms of a taxonomy as selectable options;
Ofcourse you can implement anything you want as long as it returns an associative array!!!!
See the desciption under the option field;
Hope this helps others and also hope quicksketch is willing to apply this to webform so the people can create their own components in the future :)
Cheers
Bartezz
PS. If you've downloaded, applied and tested PLEASE post your feedback here even if it works!!! I see many questions on this forum but not too many replies saying "thank you, the solution you gave me worked!". That doesn't help others nor help improving code!
Comment #60
Bartezz CreditAttribution: Bartezz commentedAnother code snipplet...
This one is what I'm using to show titles of nodes of a certain type with a certain term as select options;
Tip: Because I'm not great at SQL I use VIEWS to create a MySQL query which is nice and easy :) Be careful with single and double quotes tho. Don't mix those within the query! And be sure to check_plain the output!
Cheers
Comment #61
occupantThank you! This is just what I've been looking for. I'm able to use views to make the query and it all works as advertised.
I'm using the snippet above (#60), but I want to display the taxonomy term's value rather than it's numeric id - any tips on doing that? My php skills are pretty rudimentary.
Also, what about displaying several query values for each select component (eg. a taxonomy term and node title)? I've been playing with it for a while but ... you know... the sucking at php thing keeps getting in my way :)
James
Comment #62
Bartezz CreditAttribution: Bartezz commentedHey James,
Not sure how you are using the snipplet in #60 to show taxonomy terms but anyway... play around with VIEWS!!! In the Views UI when you create a view which isn't anything more than a db query it will give you the query used to create that particular view. That way you can change the snipplet to output anything you want.
If you want to run multiple queries and output the options within the samen select you can do something like this (probably better ways but since you don't know much about php this is probably the easiest);
Cheers
Comment #63
ramandeep.kaur CreditAttribution: ramandeep.kaur commentedI need to have a dropdown in webform where I have to populate data from a view (of all the OG's say). Is this possible....??
Comment #64
josi123 CreditAttribution: josi123 commented#60
Thank you! I've been looking for this functionality in Webform for years...
Maybe this will help someone:
If you want the select list to show more than one column from the query just concatenate the columns alias:
For instance, if we want a select showing node title plus node id with some kind of separator ("-"), all on the same line:
Just use Views to construct the query with the fields you want to show, and put the resulting SQL as the db_query parameter as shown above (to show the SQL query while editing the View you have to preview it).
As Bartezz said, don't forget to replace double quotes in the SQL statement with single quotes, ex:...WHERE (node.type in ("hulpverlener")) ... change to WHERE (node.type in ('hulpverlener')) )
EDIT
Replace single quotes in the SQL statement with double quotes, ex:
...WHERE (node.type in ('hulpverlener')) ... change to WHERE (node.type in ("hulpverlener")) )
Comment #65
Bartezz CreditAttribution: Bartezz commentedThink we can change the status now. Looks like it's working for everyone.
Hopefully it'll get comitted soon!!!
Cheers
Comment #66
pshahmumbai CreditAttribution: pshahmumbai commentedCreated a small module called 'webfromredirect' to do that :)
Comment #67
josi123 CreditAttribution: josi123 commentedI guess patch #59 doesn't work for 6.x-2.8 version?
Comment #68
Bartezz CreditAttribution: Bartezz commentedCould be I'll look into it asap (remind me when I forget, am very busy with some projects right now).
Hope that when I provide a 6.x-2.8 patch that everyone will test and post back AND that quicksketch will commit...
It's of not much use and rather contra productive to keep having to create new patches and patch new releases if the code has been reviewed and tested by the community.
Cheers
Comment #69
Bartezz CreditAttribution: Bartezz commentedHere ya go:To install Dynamic_select for D6;
- download http://drupal.org/files/issues/dynamic_select_6.zip
- unzip to sites/all/modules
- enable the module in admin/build/modules/list- donwload the attached patch for webform.module 6.x-2.8
- apply the patchPLEASE post back when you've tested!!! Also if it is working as expected....Cheers,Forget about this... posted a buggy patch.
Will work on this tomorrow....
Comment #70
Bartezz CreditAttribution: Bartezz commentedWas missing a line in my patch, dunno how that was possible but here's a proper patch.
To install Dynamic_select for D6;
- download http://drupal.org/files/issues/dynamic_select_6.zip
- unzip to sites/all/modules
- enable the module in admin/build/modules/list
- donwload the attached patch for webform.module 6.x-2.8
- apply the patch
PLEASE post back when you've tested!!! Also if it is working as expected....
Cheers,
Comment #71
botrisI tried this patch just now for the first time, but it works half...
D6 - 6.14
Webform 6.x-2.8
When I try the taxonomy (#53) way, it works. But when I try to get all the titles from a specific node type with a query, I get nothing. The SQL query is directly copied from views.
Please advice
EDIT
Ok I got it working by doing the opposite as discribed in #64. I changed the single quotes from the views query into dubble quotes and now it works.
EDIT 2
Doesn't work with Better select.
Comment #72
josi123 CreditAttribution: josi123 commentedThe new patch works (webform 6.x-2.8, Drupal 6.12).
#71 is correct. In the View query, replace single quotes with double quotes.
Comment #73
Bartezz CreditAttribution: Bartezz commentedOops my mistake :)
But I think the patch is ready to be committed then right?
Cheers
Comment #74
Summit CreditAttribution: Summit commentedYes please, would be great if this would be committed!
Greetings,
Martijn
Comment #75
bwyatt CreditAttribution: bwyatt commentedAll the examples I see above seem to only use the Drupal API database functions, which is great if I want to pull from Drupal. But what about external databases? Would it be possible to use this patch to populate options from another database?
Comment #76
quicksketchIt's been a while since I've looked at this issue, my apologies. As time has gone on, I've become less and less inclined to introduce new "execute arbitrary PHP code" options into Webform. In the 3.x version I'm hoping to remove all execution of arbitrary code, considering it's extremely dangerous potential.
So not being very keen on adding more of what I've been trying to get rid of, I had been avoiding this issue. However, I'm very happy to see the direction Bartezz has taken this, which is to simply move the option to a new component. This is great in a lot of ways, not least of which means it's something that can be added to the 2.x version so we don't have to wait for the 3.x version to come around to get this functionality. I'd be very happy to apply Bartezz's patches to all versions of Webform, since it looks like it's actually a bug/limitation in the API.
Patches are usually marked RTBC when they're ready to go in (rather than "to be ported"). It sounds like this patch has been tested already, right?
Comment #77
Bartezz CreditAttribution: Bartezz commentedHi Quicksketch,
It's not really my code. I provided a patch basically just out of what I've scavanged from this issue. Most of the credits go to bignab.
I've been using it for a while now on a semi-production site and have encounterd no problems whatsoever. (well not counting badly formed SQL statements, which will not trhow you a warning nor will it crash, it just doesn't work then).
Thanx for embracing this piece of code which I think will improve webform a lot!
Cheers
Comment #78
Bartezz CreditAttribution: Bartezz commentedI managed to find a bug after all.
When I run an analysis I get a warning;
Won't have time in the upcoming 2 weeks to take a look at this. If anyone else has a chance to... please do.
Cheers
Comment #79
omerida CreditAttribution: omerida commentedi tested the patch in #70 succesfully, would love to have this hook in webforms.
Comment #80
DoubleT CreditAttribution: DoubleT commentedThe patch in #70 is great, but what should I do to use profile token?
The default value is not selected.
Comment #81
bradezone CreditAttribution: bradezone commentedDo we know if this is working for 6.x-2.9?
I just tried the instructions from #70 and the new dynamic_select component is not showing up.
Comment #82
pixelwhip CreditAttribution: pixelwhip commentedI've also followed the steps in #70 using 6.x-2.9 and adding the 2.8 patch manually. I'm not seeing the dynamic select component on the webform config page or when adding components. Any thoughts on why this might be?
Thanks for all the work, this will save me from the tedious work of creating and maintaining huge select lists!
Comment #83
Bartezz CreditAttribution: Bartezz commentedHi all,
Finally had time to take a look at the minor bug mentioned in #78.
I also created a patch for webform 6.x-2.9.
For those who have a problem with dynamic select or the patch => I have this working on latest versions of Drupal core & webform.
If you have problems, try clearing cache. If you have other problems... you probably haven't followed directions.
@DoubleT #80, I have no idea how to use profile token. I reckon you should create an issue in the Post Installation forum on how to load tokens...
Quicksketch will you commit this?
Cheers
Comment #84
josi123 CreditAttribution: josi123 commentedThis is an important funcionality for me. Stopped updated Webform to avoid breaking this patch. I will try the new patch. Thanks again Bartezz!
Comment #85
ikeigenwijs CreditAttribution: ikeigenwijs commentedSubscribing
Comment #86
bradezone CreditAttribution: bradezone commentedNew patch/module works great with webform 6.x-2.9
I'm using code very similar to #71.
Thanks!
Comment #87
josi123 CreditAttribution: josi123 commentedThe patch from #83 also works for me with Webform 6.x-2.9
Comment #88
Lanae CreditAttribution: Lanae commentedWorks for me too! I'm using Webform 6.x-2.9 also and D6.15. Thanks Bartezz for this patch!
One minor issue, the descriptions I enter for the dynamic_select fields are ignored, and instead they all only use 'Hold CTRL and click for multiple selections'. Any tips for fixing this would be great...I would like to customize the help hint for each field, like the rest of the webform elements.
Comment #89
quicksketchNote that I've reworked the entire component system over in #340241: Provide hook_webform_component_info() to allow 3rd-party components, but only for the 3.x version. The approach differs significantly from this patch, considering the 2.x version of the component system has several deficiencies that make it difficult to extend properly.
Comment #90
Bartezz CreditAttribution: Bartezz commentedHey quick,
Thanx for letting us know, haven't been paying attention! :)
Do I have to rewrite the dynamic_select for it to work with 3.x?
I currently do not have much time to do so, kinda hoping someone else will pick this up!
Cheers
Comment #91
quicksketchYes it will need to be updated, but I wouldn't be in a hurry to do so. The APIs are still changing in the 3.x version are likely to change. There's about to be another large overhaul to address #181077: Printable page for webform submissions, which requires that components provide HTML output of their data.
Comment #92
joelstein CreditAttribution: joelstein commentedHow about a totally different direction for this ticket... why not simply integrate Views? Views already does all the "dynamic selecting" you could hope for, and then it keeps custom PHP out of the UI. Something like CCK has for the node reference field type. You could specify your own select options in a textarea, or choose a Views view, which will dynamically populate the select for you.
Comment #93
Bartezz CreditAttribution: Bartezz commentedSounds like a good idea at first thought... yet I don't have time to implement such a thing...
Cheers
Comment #94
manogolf CreditAttribution: manogolf commentedTrying to follow what is going on here I'm really unsure of the end goal?
What I would like is a way to display on the site the number of users that have completed my webform. A counter display of submissions.
Will using this patch help?
Comment #95
marcvangend@#94: No, that's not what this patch is for. This patch is meant to populate a select box with the results of a database query. For instance, you have a content type "brochure" and visitors can order brochures by filling out a webform. In that case, you need a select box which contains the titles of all brochure nodes.
Comment #96
manogolf CreditAttribution: manogolf commentedWow. Sounds like a real handy feature. Thanks for the clear explanation.
Comment #97
lorenlang CreditAttribution: lorenlang commentedsubscribing
But personally, I'd really like to be able to use straight PHP as well. I've got some selects that change on a regular basis and I could easily program them to stay up to date that way. Things like a dropdown list of the past 20 years or the next 5 semesters based on the current date end up getting out of date until someone happens to look and remind us.
Comment #98
John Pitcairn CreditAttribution: John Pitcairn commentedAhhhh, crap!
Finally updated webform and it seems we can no longer access the session variable array for anonymous users. I was relying on that (#48).
Looks like I'll need to try this module/patch. Rats, more work.
Comment #99
John Pitcairn CreditAttribution: John Pitcairn commentedWorks nicely, and not much work at all, many thanks. Would be good if this patch could get committed.
Comment #100
John Pitcairn CreditAttribution: John Pitcairn commentedUrk ... not so fast. The dynamic select element's default (selected) option cannot be set by %get[].
I'm thinking this might be a bug, other form element default values are successfully selected by %get[].
Can anyone else reproduce this?
Comment #101
John Pitcairn CreditAttribution: John Pitcairn commented#76: If the desire is to avoid parsing arbitrary php, how about allowing select elements to be populated by a named drupal variable? Then the module just needs to check that the variable contains an associative array.
Similarly, it would be really useful to allow default value fields to accept variable input (now that $_SESSION is not allowed for anonymous users) - I have a situation where I need to set a different default depending on certain conditions, but I don't want that in the URL.
Comment #102
bocky CreditAttribution: bocky commentedI am using code:
to get data from field_mdatum (multi-value date field). Everything is working fine, it shows data in format: 2010-02-02T00:00:00.
What i would like to do is to show date in short format (or custom).
I tried with check_plain(format_date($record['node_data_field_mdatum_field_mdatum_value', 'medium'])); But this returns 1.January 1970 for all entries.
Thanks for help:)
Comment #103
kostajh CreditAttribution: kostajh commentedPatch and module in #83 work fine for me. Would be good if it was committed to the 2.x branch.
Comment #104
quicksketchWe have an alternative mechanism in the 3.x branch, making this unnecessary there. Since it's an API change and support for 2.x is ending quickly, I'm not inclined to commit this. We'll probably only have one more 2.x release ever before support comes to an end, I'd prefer we don't build a dependency on *exactly* the 2.10 version of Webform, since there will be no more releases after it in the 2.x branch.
Comment #105
kostajh CreditAttribution: kostajh commentedHi quicksketch, what is the alternative mechanism in the 3.x branch and how does one utilize it? Is there any documentation?
Comment #106
quicksketchkostajh: the functionality was added in #340241: Provide hook_webform_component_info() to allow 3rd-party components. All of Webform's new hooks are documented in the webform_hooks.php file included with the 3.x version of the module.
Comment #107
kostajh CreditAttribution: kostajh commentedI'm a bit confused by how to work with this API.
In the 2.x branch, a patch and light-weight module were offered #151603: Can I put options in a select field from a database query? to allow dynamic population of a select menu via PHP. So for example, I could call a function that loaded a view, gathered the objects, and populated the select menu with those items. This was easy to implement in a few dozen lines of code. However the patch was not committed in favor of Webform API in the 3.x branch, which would allow other modules to declare their own components. That's fine, and I understand the reasons for doing this.
However, now I am looking at the Webform 3.x API (http://drupalcode.org/viewvc/drupal/contributions/modules/webform/webfor...) and trying to understand how to implement the same functionality that was possible with 2.9 and the dynamic select patch, with little success. I imagine there are must be others in the same boat. All I need is a select menu that is dynamically populated via PHP (in my case, with a call to a function in a custom module that returns an array). Unless I am missing something obvious, it seems like trying to do this with the Webform 3.0 API would require several hundred lines of code.
Could any of the developers who are familiar with the Webform 3.x API provide some guidance? Thanks.
Comment #108
quicksketchHmm, are you talking about the module in #83? That module is only 10 lines, but the component is about 400 lines. The 3.x approach works the exact same way only instead of "hook_load_webform_components", there is "hook_webform_component_info", which provides information such as a translated name and description, as well as some capabilities of the component.
Note that I'm still open to #406486: Allow pluggable select list values (which has been left open separately intentionally), which simply suggests a hook be added to select.inc to provide a list of key/value pairs. This issue has long focused on making a new component, versus #406486 is about adding a hook to the existing select.inc.
I'm moving this to "to be ported", even though the module provided in this issue will never be part of the Webform project itself.
Comment #109
kostajh CreditAttribution: kostajh commentedThanks quicksketch. I'll see about porting dynamic_select to 3.x, although I think you are right that the approach in #406486 makes more sense.
Comment #110
luthien CreditAttribution: luthien commentedhello, while waiting for the dynamic select to the part of the 3.x API, does anyone has a working version for the #83 patch or an alternative way of achieving the desired results for 3.x? I need to populate my webform fields from an external database but I could not find a way of doing it with 3.x.
I also have an extra question for quicksketch, it is not related with dynamic select: How to display the value from a particular field as part of the email subject? example: I have two fields, last name and first name; if I want to send the email with those two field concatenated in the subject, how do I do it?
thanks.
Comment #111
quicksketchluthien, please do not post unrelated questions in the same issue. I don't think there is an existing issue for your question, so please post a new one.
Comment #112
kostajh CreditAttribution: kostajh commentedHi Luthien, I'm working on finishing up the port of Dynamic Select module to the 3.x API, and aim to be finished up by the end of the week. It's functional, just need to clean up some of the code before sharing.
Comment #113
jackylam CreditAttribution: jackylam commentedSubscribing
Comment #114
felipe CreditAttribution: felipe commentedSubscribing
Comment #115
kostajh CreditAttribution: kostajh commentedI applied for a CVS account today with the completed Dynamic Select code. I'll let you all know if/when that gets approved and when I create the namespace on drupal.org for the project.
Comment #116
quicksketchIf considering make a new project, I'd recommend making a module for ALL custom Webform PHP code. Since I'm dying to kill off the "Additional Processing" and "Additional Validation" fields (and I will remove them in one way or another in 3.x). If #406486: Allow pluggable select list values were put in place, then you could simply extend the existing select.inc instead of making a new component, which would be much better from a maintenance point of view. Then we could put all the custom PHP functionality of Webform in one place, and I wouldn't have to deal with the support requests from people breaking their sites. ;-)
Comment #117
luthien CreditAttribution: luthien commentedHi kostajh, I will be the first one to use it. All my webforms requires custom PHP code. Thanks!
Comment #118
kostajh CreditAttribution: kostajh commentedHi quicksketch, that's a good idea. However, for the moment I'd like to get the Webform Dynamic Select project out since many people can set it up and use it right away. I will take a closer look at #406486: Allow pluggable select list values and think about your idea for a Webform PHP module when I have some time later in the month.
Comment #119
luthien CreditAttribution: luthien commentedHello kostajh, where can I get a copy of your updated code to test it? thanks
Comment #120
jackylam CreditAttribution: jackylam commentedHi, I will be interested to test as well.
Comment #121
kostajh CreditAttribution: kostajh commentedIt seems like the CVS approval process might take a while, so until the project is approved those who would like to test the Dynamic Select module for Webform 3.x may do so by downloading the tarball here: #746366: kostajh [kostajh]
Comment #122
luthien CreditAttribution: luthien commentedThe Dynamic Select module is working great, I'm using it in a production site to display content extracted from an external database.
Comment #123
quicksketchThe subscribers in this issue would likely be interested in these two issues:
#406486: Allow pluggable select list values
#754580: Remove Custom PHP Execution (Additional Processing/Validation) Fields
This makes the dynamic select module largely unnecessary, because there is now a hook in the normal select for populating lists. kostajh, rather than starting a new module, it would be really great if you could extend the split-off module http://drupal.org/project/webform_php instead, making it a one-stop-shop for people that want to type PHP code into textareas.
Comment #124
ybthefurste CreditAttribution: ybthefurste commentedCore 6.16, Webform 2.9
- works just fine -
Comment #125
luthien CreditAttribution: luthien commenteddo you have a rough guide on how to create the hooks? i.e. what files needs to be modified, etc.
Working like a charm with version 6.x-3.0-beta5!
I added my hook here: sites/all/modules/webform/includes/webform.options.inc
The only problem I see is with future module updates overwriting the file above and loosing custom code.
Comment #126
quicksketchluthien, the documentation for hook_webform_select_options_info() is in webform_hooks.php (included with Webform), you just need to put your hook into a new module and then you can create your own webform select options there.
Comment #127
luthien CreditAttribution: luthien commentedthanks quicksketch for the prompt reply. I still need to use the dynamic select module as I have to dynamically populate a second select by passing the value of the first one as a reference for my query.
Is there any other way of populating your select component dynamically? creating a custom hook is not going to work if I don't know how to pass the value from initial selection to the second select. Kind of the country > city example, select country then populate city based on selected country but, in my particular case, I don't know what results will be displayed for first select (dynamically generated, not static values) thus not being able to create options based on first value.
Comment #128
adeb CreditAttribution: adeb commentedSubscribing
Comment #129
benmmc CreditAttribution: benmmc commentedHere is a simple post on implementing hook_webform_select_options_info(), which is the hook provided in Webform 3.0-beta 5.
http://fleetthought.com/programmatically-adding-pre-built-option-lists-drupal-webforms
Comment #130
luthien CreditAttribution: luthien commentedHi engineindustries, implementing the hook was easy to do following the instructions from quicksketch above. The functionality I need, and it is not easy to implement, is an option to populate a list dynamically based on the first dynamic list selection. Even more extreme, my lists are populated with options from an external database, so I need a way of passing the initial selection key to populate the second select after using the key to query my external db. I was able to the desired functionality using the dynamic select module, but that module was not saving the results for the submission thus it was not perfect.
Comment #131
mnapthine CreditAttribution: mnapthine commentedNice simple post here if anyone is interested:
http://www.designhammer.com/news/providing-dynamic-select-options-to-web...
Comment #132
MattBrigade CreditAttribution: MattBrigade commentedDude, thanks!
Comment #133
quicksketchNot sure why this post is open still.
Comment #134
Ludo.RJust to be sure :
Are dynamic select options (e.g. list of nodes) now possible through hook_webform_select_options_info()?
With Webform 6.x-3.x of course!
Thank you!
Comment #135
luthien CreditAttribution: luthien commentedyes, dynamic select options are now possible. The only problems I'm experiencing with dynamic selects in webform module are the reports. I have a dynamic select (populated with a query to an external DB) that was implemented using hook_webform_select_options_info(). The web form works fine, values are submitted correctly. The problem is when one of the values of the dynamic select is not an option anymore because it has expired, then the report fails. To generate reports from those web forms with dynamic fields, I'm using the webform_report module that works very good. The module is actively maintained and the developer adds new functionality to the module almost every day, we just need to wish for it.
Comment #136
Ludo.RGood to know that.
Thank you for your feedback, i will check that next time i'd need it.
Comment #137
jorisx CreditAttribution: jorisx commentedjust a node ref option from cck to webform would be very nice,
thanx guys... gone try the module option for now :)
Comment #138
loominade CreditAttribution: loominade commentedhook_webform_select_options_info()
I love you guys
Comment #139
theoracleprodigy CreditAttribution: theoracleprodigy commentedWhile the above does work with some modification... I have another question. How do you break up the data from the display. What if what you want to post is numeric but the title is what you want to display:
example:
select amount, display from x
I thought you would just return the list as:
$array[$row['amount']] = $row['amount'].'|'.$row['display'];
However this did not work.
Comment #140
vasanthkay CreditAttribution: vasanthkay commentedThe dynamic select module created by kostajh (http://drupal.org/node/746366) is very useful... I used it in one of the form I created.
As luthien had pointed out in that thread, 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 #141
kostajh CreditAttribution: kostajh commented@vasanthkay: check out hook_webform_select_options() in the webform_hooks.php file in Webform 3.x.
Comment #142
luthien CreditAttribution: luthien commented@vasanthkay, I used the new hook from webforms to populate the dynamic select boxes and the webform_report module to generate the reports.
Comment #143
Squiggles CreditAttribution: Squiggles commentedIs there a version of this for Webform 4? Would be nice if this was available. :)