I implement corporate marketing websites, which often have contact forms. I've implemented four since March, am currently working on a fifth, and all of them had conditional routing: They went to one or more selected people, based on characteristics of the form.
For example:
- if the person filling the form self-identifies as a "member of the media", the form is routed to the PR person.
- if the person checks a box to request a sales visit, the form goes to the sales manager
... and so on.
Webform has everything I need except this.
My experience leads me to believe this would be a pretty common need. The Feedback form can do single-person routing, but it can't easily be expanded to include extra fields. (That's a requirement. Clients always want way more information on their feedback forms than is there in the Drupal feedback form. Not directly relevant, here, since webform addresses that, but that's why I can't use feedback.)
I found a patch to implement something that looks like this in the 4.6 version of webform, and I've looked at the patch code to see if I could adapt it. But:
- I've got no experience with the Drupal API
- My php skills are not at the level that allows me to grok this stuff quickly and easily.
- That said, looking at the patch code leads me to think the 4.6 and 4.7 versions of webform are pretty seriously different, and I'm having a hard time figuring out where the 4.6 patch relates to the 4.7 code.
So, I'm posting this as a feature request for 4.7, even though there is a 4.6 patch.
Comments
Comment #1
quicksketchHi there escoles, I know it's been a while since you posted this request (we've had it before, without much progress), but I'm posting because a recent addition to webform CVS version might be able to help your cause. I added in two additional fields in the "Advanced Settings" of webform for 'additional validation' and 'additional processing'. This basically allows you to perform additional verification on fields (like phone numbers or URLs, etc) and also perform additional tasks after the form is submitted (like sending out extra emails).
The learning curve is pretty steep, and it basically requires some knowledge of Drupal and PHP. Since I just put this to use, I'm posting my code as an example.
I put together an advanced submission form for inviting new users to a site. It asks for email addresses of a users friends, then checks if they are currently a user of the site. If a user is registered, it throws an error. If none of the new email addresses are registered users, then an email is sent out to all users 'inviting' them to join the site. Here's the code to get started:
The validation code:
And the additional processing code:
I hope this helps.
Comment #2
escoles commentedWhen I've got breathing room after the current project, I'll check it out.
Comment #3
quicksketchI've linked to this page from the webform project page to help others get started with validation/submission code.
Comment #4
BioALIEN commentedJust what I was looking for. Cheers quicksketch :)
Comment #5
nshreders commentedI previously wrote a patch for webform 4.7 to prepend text in the subject line. 5.x allows for additional processing but I'm not able to get it to work. I tried:
So the email sent out will have the subject of "dummy_text: ". It's just showing the I have set for the subject. Does anyone have any suggestions? I'm doing this so recipients can setup filters in their email clients.
Comment #6
Marc Bijl commentedHi,
I stumbled upon this page looking for a way to send a confirmation e-mail to an (anonymous) user after submitting a webform. The code here seems to be what I was looking for, so that's the good news. The bad news however: it gave me an error.
I'm not a programmer, but I think the function user_mail needs to be replaced by drupal_mail:
- http://drupal.org/node/64279#drupal-mail
This seems to work :)
But, a $mailkey is needed. Can anyone please explain (idiot proof) what this is and which value(s) I can use?
Cheers,
Marc
BTW
I like to include an order number or something in the confirmation e-mail, e.g. the value of the submitted field in the submissions table. Does anyone know how to achieve this? Many thanks in advance!
Comment #7
quicksketch@New Oceans, good question. The code posted above was for a 4.7 site, which used user_mail(). The function has now be renamed to drupal_mail() and has new super powers. :)
The $mailkey parameter you mention can be anything you like. I recommend something like "webform_anonymous" or "webform_nid_x", so that it correlates to your particular use-case. This "mailkey" is used by hook_mail_alter(), so any module may modify the mail as necessary (like creating an html mail which automatically adds links for http addresses).
So, just make it whatever you like. You'll probably never need to reference it, but follow good practice and make it something unique and relevant.
Comment #8
neurojavi commentedHi:
This is what I was looking for!
But I'm unable to find those 2 options for additional validation and processing it in the 5.x version of this module?
Is there a patch or have I to use the HEAD version?
Many thanks.-
Comment #9
neurojavi commentedops! Please forget my message above. I've found those options! It was a problem of mine.
Sorry for the noise.
Comment #10
ellen.davis commentedI am having the same issue as the original author of this thread. I need to route the email by Topic. I created a webform with a drop down list of Topics. Can the additional processing change where the email is sent to depending on the Topic?
Comment #11
rick hood commentedYour comment is old, but I had to do the same thing so am posting what I did here.
I followed the basic method that quicksketch outlined.
First, I wanted to put all my form processing code in another separate file, so I could just work on that file, so in the 'Additional Processing:' field on the web form, I put this:
…so now I am just working on the 'inquiry_process.php' file and I stuck in the folder called 'process'. You don’t have to do it that way, you can just stick the code below in the 'Additional Processing:' field.
Here is the code:
Comment #12
tsernobyl_good_times commentedFor me this script doesn't seem to work. I tried recreating the example - I made components 'Topic' (with same options, Religion, Politics and so on) and a textfield 'Comment'. When I try to send a form, all I get is a following error message:
I parsed the script line by line and it seems that the error is in following part:
Comment #13
rick hood commentedAfter my above post I found I was having trouble with drop down choices that were multiple choice.
This does not work for 'multiple-choice-allowed' drop downs:
But this does:
Comment #14
CMatters commentedOk.. this is probably going to come very close to going in the stupid question category. I have found this thread very useful and has resolved a major issue.
However, I have one concern... When using
$component['name'], the code will look for the "human readable" field name for a form. I'd rather use the machine readable name assigned to the field. I see it shows up in the rendered HTML source of the form. Is there a way to do that?For example, right now I am using
When I'd rather be using
Thanks!
Comment #15
rick hood commentedI believe you use this instead:
$component['form_key'] == "daytime_phone"
I found that by looking in the database table called 'webform_component'.
Comment #16
ThadC commentedAnyone know how to make the FCKeditor module play nice with webform? When submitting a webform I get an error which reads:
Any ideas?
TJ
Comment #17
ellen.davis commentedHere is what I came up with. I do not use drupal_mail to send the email. Rather, this script sets $node->email and lets webform send the email.
Comment #18
archetwist commentedWhat about the 2.x version of the module? I've tried to modify the code but with no success. Could someone post an updated snippet?
Comment #21
abraxsus commentedI've just started with Drupal - and think it's great - and Webform. Today I made my first form with a datefield, but it doesn't automaticly check the input (year field) if it's a correct date. Also the year range has to be between 1920 to 1991. I've been strugeling to find a solution, but my knowledge of PHP and the Api is minimal. Is there anybody who can help me out?
Comment #22
quicksketchI've started a series of handbook pages on using the additional validation and submission fields under the main webform handbook page. Please post any new snippets there: http://drupal.org/node/197550
Or if you have a request for a new snippet create an issue.
Comment #23
nina_bee commentedHi,
I also try to add aditionnal processing to my form. I have a form that non-autentified and autentified users can access to order. I need to check the email adress. If the email adress is unknown, then the user us automatically regisered with is first name as a login and his email adress as a password. Then he recives a mail with his infos. If the user is already regisered then nothing else happens.
This is the code (based on quicksketch's code above) :
Additional Validation
This send me an error :
Parse error: syntax error, unexpected T_STRING in /homepages/14/d239557980/htdocs/drupal/modules/webform/webform.module(1458) : eval()'d code on line 6
Parse error: syntax error, unexpected T_STRING in /homepages/14/d239557980/htdocs/drupal/modules/webform/webform.module(1504) : eval()'d code on line 15
Do you have an idea?
Thanks
Comment #24
isaac77 commenteddavis4104: thank you for that code snippet, it was very helpful.
archetwist: The code in the example provided by davis4104 needs to be modified for use with webform 5.x-2.* I'm not an expert with this module, but here's what worked for me:
$node->email = $ToEmail[$value];needs to be changed to
$node->webform['email'] = $ToEmail[$value];also, in webform 5.x-2, you can set "additional" emails like this:
Of course you do not have to use advanced -> additional processing to set those "additional emails" in all situations... In some cases, it is easier to set those values in the e-mail address and 'conditional e-mail recipients' fields.
Comment #25
j2g2 commentedHi, where do you place the php code? In what file?
Thank you for your help.
Comment #26
ericcorriel commentedFor anyone using Webform 6.x-2.4 you may want to use the following code as the code above (which makes reference to $node->webformcomponents) is, I believe, no longer valid in 6.x.-2.4. I use the following to check for a valid email address:
Comment #27
m.e. commentedI've been through several of these posts and tried various validation snippets without success. Is there some clear documentation that I've missed? How do we know what will work in which version of Webform?
My site has 6.x-2.4 installed. Code like what was posted above by noblends doesn't break my page, but it also fails to identify invalid submissions.
Can someone who has successfully appeased the 6.x-2.4 Webform gods please provide a very basic primer that clearly shows which elements in the code snippet are standard to Webform and which are just examples of variables in her/his page? (For example: is 'submitted' common to all Webform code? is 'name'? is $component?)
Comment #28
quicksketchCheck out the webform documentation at
http://drupal.org/handbook/modules/webform/submission-code and
http://drupal.org/handbook/modules/webform/validation-code
for some more examples. All snippets should work in any version of Webform 2.x. The only variables that are available are $node and $form_values, everything else comes out of those two variables.
Comment #29
m.e. commentedThanks - I actually read the validation-code page, couldn't get anything to work, and posted a comment there that no one has answered. (My code has changed twice since I posted that comment - still no luck.)
I have a grid with dollar amounts (labels like "$100" "$25" ... "Other"). Database name for this choice is 'set_amount.' Below the grid is a textfield keyed as 'typed_amount.' If "Other" is selected in the grid, I want to require a numeric value in the textfield.
I'm pretty sure I'm just not getting how to properly reference the selections in my IF statements. It might help if the snippets included examples of labels, keys, etc. for the Webform components being validated.
Comment #30
jamescross commentedHi, I have created a food order form and I need users to submit the date and time they wish to collect their food. However, after 10:30am I do not want the date field to display today's date as an available collection date. Do you know if I can achieve this using the additional validation section.
Thank you
Comment #31
quicksketchPer the submission guidelines, help with custom coding including theming, custom validation, or form_alter() is not provided in the Webform issue queue. I'd suggest referencing the handbook pages as noted in #28.
Comment #32
sdmaxey commentedIs it possible to use the Additional Submission to send the field values off to an external SOAP server so that our email provider can do double-opt-in validation. I was able to build a simple php form outside of Drupal that worked, but of course didn't have the validation and security within Drupal and webform.
There are hints here that suggest a possible path for what we want to do, but others that make me think its not possible. I've already read the documentation.
#11 suggests a way forward, but I seem to be missing the point where I can send the data using the nuSOAP client to the SOAP server instead of the webform data table.
Can someone point me in the right direction?