Closed (won't fix)
Project:
Webform PHP
Version:
6.x-3.x-dev
Component:
Webform PHP
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Aug 2008 at 05:23 UTC
Updated:
4 Feb 2016 at 07:48 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
lefnire commentedor alternatively, could provide a text-area for php-determined default-values... maybe in the component's advanced fieldset or whatnot.
Comment #2
lefnire commentedscrap my %session comment, I think a custom-php box for default values would be really useful. Doing some pretty advanced pre-population stuff on forms, and I've been exposing a bunch of data in $_SESSION in order to do it in PHP.
Comment #3
fabio61 commentedHere is a solution. It is some source from my app. (5.x.2.2) . You can use php tag in default value.
1. This is a patch (or hack) what you have to insert into the webform.module file in the newest version from line No. 1920.
2. Choose the Webform Edit / Form Coponents / Something Component / Edit.
In the default value field you can use php code, calling a function, for example:
If you use the select component, you can call a function from the settings field, and the function returns with the right string...
3. You have to call these functions from an included file. I include this file in the index.php after the bootsrap.inc
4. The content of lib.php is something like this
Comment #4
daniorama commentedFabio61, could you explain a bit more how to use that code or where should I put it? What I want is to use values from tables of my database in the default value of a webform, quicksketch told me php is not supported, what can I do then to make an SQL query? Thanks!
PS: by the way, I'm using the D6 dev version, I hope this will work also there.
Comment #5
uberellis-dupe commentedDitto for me. Would like to fill out default values from Bio or Nodeprofile based on currently logged in user (using 5.x version however). Default values for CCK fields have the same issue unless using the profile module.
Comment #6
murzsubscribe
Comment #7
quixote commentedFabio61, your method/hack works great. And just in the nick of time in my case, so extra special thanks to you!
In addition to your examples for output, I have found that
$var = "whatever";also works, and will by default return the value of $var. Obviously you can use any $stringname. $_SERVER (and probably $_SESSION) variables work too, which I used to create a link to the node in a hidden field (as my form is embedded in another node).
Anyway, nice work!
Comment #8
asciikewl commentedI needed the same feature, but preferably with some access control over who can use php for default values.
It was a little bit tricky as the permission should come from the author of the webform, not the current user.
Also I've used drupal_eval to make it a little bit less hackish :) It has the effect that instead of returning a value in the php code, you just need to print it, which is more like what most of the other cases that allow php tags in cases like this where you can have mixed text, tokens and php.
Attached is the patch.
Comment #9
asciikewl commentedI've updated this patch for webform-5.x-2.4
Comment #10
Cory Goodwin commentedI implemented this patch on a local install. I played around with different things. Everything worked as intended. I tested different default php strings. Also tested different user roles with different user settings. Everything worked. I vote for this to be committed, full php is very useful.
Nice work AsciiKewl.
Comment #11
Whiskey commentedI manually applied the patch to 6.x-2.4 and it seems to work fine. Created a patch that should work (first time creating a patch though..)
So I second to commit this one, thanks AsciiKewl!
Comment #12
codevoice commentedI vote that this gets included in the HEAD, it's incredibly useful!
Comment #13
detot commentedsubscribe
Comment #14
asciikewl commentedI just tried and the patch still works vs. 5.x-2.6
Comment #15
deepak@1your.com commentedwebform - 6.x-2.6
#11 does not seem to work for me as it is.
Had to change
if (strpos($string, '<?php') !== FALSE && arg(0) == 'node' && is_numeric(arg(1))) {
to
if ((strpos($string, '<?php') !== FALSE)) {
to get this fix working. However I am not sure of the implications of the removed code. Could anyone please shed some insight into this problem?
Thanks,
Deepak
A collection of Java and other tutorials/articles
Comment #16
TimG1 commentedsubscribing
Comment #17
cayenne commentedI want! I Want! Subscribing.
Comment #18
asciikewl commentedFresh patch of this vs. 2.7 Works for 5.x and 6.x
Comment #19
quicksketchAsciiKewl, I really appreciate the reroll, but I'd prefer to not add this functionality. I'm doing everything possible to *remove* custom PHP fields from Webform by providing more robust options for validation and submission. If this functionality is added, it'll need to be in an add-on module. In any case new features are only being added to the 3.x version.
Comment #20
asciikewl commentedNo probs. I have to re-roll for D5 as I have a site using it, so I might as well post it in case someone else is using it as well.
So far I've used it for 2 use cases: Pull a profile field from the user filling in the form into a hidden field and fill in a hidden field with a custom format date (YYYYMM in this case), both which then become available for quick drill down functionality in the analysis.
I'm pretty sure both could be done in another way, php just seemed to be the quickest at the time.
Is there anywhere a writeup/roadmap with what you're planning for webform 3? Maybe I can help.
Comment #21
irozner commentedhey,
can someone port this patch to version 6.x - 2.8 and upload the entire webform.module file (or send it to me)? i need it ASAP!!!!
thanks in advance!
Ido
Comment #22
asciikewl commentedThe 2.7 patch posted above still works for 2.8 and 2.9. (with some offsets, which should be fine).
To patch it, cd into the webform directory and do:
patch -p1 < webform-php-defaults-2.7.patch
Comment #23
quicksketchAs noted in #19, I won't be adding any additional "Custom PHP" fields to Webform. I'll likely move the existing Additional Validate and Processing fields to a separate module, in which case this functionality can be added there.
Comment #24
vacilando commentedI also urgently need to fill in default values using PHP :-(
I will try asciikewl's patch for now but I also hope there will be a proper way to do this in the future. (Already there are so many ways Drupal can be wrecked via PHP -- e.g PHP filter for body or CCK -- but it's all responsibility of the admins and developers!)
Comment #25
vacilando commentedIs there a patch / way to do this currently in Webform 3?
Comment #26
quicksketchThis will never be added to Webform core. Moving this over to the Webform PHP project.
Comment #27
quicksketch#1043088: This project is abandoned, please stop using it
Comment #28
surendra77c commentedIn hook_form_alter you can set the default value by php code
$form['submitted']['myfield']['my_date']['#default_value'] = date("Y-m-d h:i a", time());