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 am creating an RFP section on my site. Users can post a job (the content type) and in that node they add in their email address.
I created a webform "Submit a quote" ... I was hoping I could attach that to every "Job" content type. Then, it would get emailed to the email field from the node. It would also include the node title, author, and date.
Is there a way to do this?
Comment | File | Size | Author |
---|---|---|---|
#23 | Error_mail.jpg | 159.45 KB | mariusm |
Comments
Comment #1
MrPeanut CreditAttribution: MrPeanut commentedI thought I searched, but it looks like I didn't do a very good job. Here is a similar issue: #1397458: Default webform attached to new content.
Comment #2
quicksketchGreat, thanks for searching. I think I've already given my best answer in that other issue. webform_default_fields.module is probably the best (or at least easiest) way to go.
Comment #3
MrPeanut CreditAttribution: MrPeanut commentedI couldn't quite figure out webform_default_fields, but I did find this post by you but had trouble with that as well. (Here's my comment in that thread.)
This is the error that I get:
Comment #4
MrPeanut CreditAttribution: MrPeanut commented@quicksketch Is this code not valid for Drupal 7?
I'm trying to get the data from field_email (my node field) into the email field of my webform.
Comment #5
MrPeanut CreditAttribution: MrPeanut commentedI am notorious for searching hours upon hours, finally asking for help, then figuring it out.
$form['submitted']['email']['#value'] = $node->field_email['und'][0]['email'];
Comment #6
prezaeis CreditAttribution: prezaeis commentedhey man
im trying to achieve the exact same thing, but im not having any luck, ive put the code in a new module and installed it but its not working
can you give me a quick run down of how u did it? maybe upload the module as well? id really appreciate it
Comment #7
MrPeanut CreditAttribution: MrPeanut commentedI downloaded the module from this comment, changed the info to be a Drupal 7 module, then just updated the webform ID and CCK field using the code from my comment (#5).
Add the webform block to your pages, check 'Show all webform pages in block' on the config, and you should be set.
To test it, you can try just the title (comment out the CCK field) and set a default email address. See if it captures the title and emails.
Comment #8
yatil CreditAttribution: yatil commentedDid basically the same thing and it didn’t work out:
My module says:
and there are even the right values in the HTML hidden form elements. But when the form gets actually sent, both values, the e_mail_to and the nodetitle are empty. I can see the sent forms on the results pane, but there is no email sent. How can that be?
Comment #9
MrPeanut CreditAttribution: MrPeanut commentedThis is how I troubleshooted it. Set up an email in the webform (node/#/webform/emails) to go to your email address only. Submit the form. Did the two fields have values? If not, your module code is incorrect.
For me, it was $node->field_e_mail_adresse['und'][0]['value']; needed to be $node->field_e_mail_adresse['und'][0]['email']; (email instead of value).
Comment #10
incaic CreditAttribution: incaic commentedHere's another solution. The following module code exposes the current top level page node through tokens, which I called "page-node". It's similar to the code in the Token module. I called the module page_node_token. I had to also create a hook_field_display_alter() function to take care of fields being displayed without a default_token_formatter. This is needed if you are using the email module.
After installing this module you will see a "Page Node" family of dynamic tokens when you are editing a form component. This allowed me to use my top level email field by entering [page-node:field_email].
Drupal 7.15
Webform 7.x-4.0-alpha4
Token 7.x-1.2
page_node_token.install
Increase module weight so that page_node_token_field_display_alter() is executed after token module
page_node_token.info
page_node_token.module
Comment #11
jainparidhi CreditAttribution: jainparidhi commentedHello incaic,
Thank you for modifying the module code for Drupal 7. However, I tried using your code and it did not work for me. I removed the php tags in your .info file as it was giving an error. The Page-node dynamic tokens do not show up in form component settings. I do not nee email field, rather another CCK field to populate a webform hidden field. Please let me know if I am doing something wrong...
Thank you so much for the input!
PJ
Comment #12
incaic CreditAttribution: incaic commentedI changed the php tags to code tags for the .info file in #10 above. This should work for Drupal7 nodes with fields you created. It should show you all the available fields. If you see some, but not the one you want, then you probably used a contrib module field type (i.e. email) that doesn't have a 'default_token_formatter' set in its hook_field_info(). If so, you would need to add a new case for the switch statement in page_node_token_field_display_alter().
Comment #13
hockey2112 CreditAttribution: hockey2112 commentedincaic,
I installed your custom module (Drupal 7), but I am not seeing any additional tokens when I edit my hidden webform item. I am trying to use a single application webform for any number of available job positions, and I want the submission to include the name of the job being applied for. The Webform is placed as a block on each job's page... can your module be used to somehow capture the job name from that page and include it in the submission?
Comment #14
incaic CreditAttribution: incaic commentedhockey2112,
Your setup sounds similar to mine. How do you build out the job's page? If the job is a node type then I would suggest using Display Suite to create the page. Then, when viewing the job's page the job node would be page_node in the custom module.
Hope that helps.
Comment #15
hockey2112 CreditAttribution: hockey2112 commentedincaic,
I am using Display Suite to manage the display of my job content type's fields. In the Manage Fields tab for job content, I have Body and my Webform.
In the webform, I created a hidden field with "%page_node" as the value... it simply returns that text ("%page_node") in the form submission. If I use %title, it gives me the title of the webform itself (not the title of the job's page, which is what I need.
On the webform's hidden field page, these are the tokens it lists:
Basic tokens
%username - The name of the user if logged in. Blank for anonymous users.
%useremail - The e-mail address of the user if logged in. Blank for anonymous users.
%ip_address - The IP address of the user.
%site - The name of the site (i.e. Deep River Snacks)
%date - The current date, formatted according to the site settings.
Node tokens
%nid - The node ID.
%title - The node title.
Special tokens
%profile[key] - Any user profile field or value, such as %profile[name] or %profile[profile_first_name]
%get[key] - Tokens may be populated from the URL by creating URLs of the form http://example.com/my-form?foo=bar. Using the token %get[foo] would print "bar".
%post[key] - Tokens may also be populated from POST values that are submitted by forms.
I'm sure I am missing something somewhere. Hopefully something above sticks out to you. ;)
Thanks!
Comment #16
hockey2112 CreditAttribution: hockey2112 commentedincaic,
It looks like my issue is the fact that I am using Webform 3.x. Is it possible at all to use the custom module with 3.x, or is 4.x required?
Comment #17
incaic CreditAttribution: incaic commentedWebform description says, "If you want Drupal 7 style tokens or use conditionals, you should install the 4.x branch."
If you are able to, upgrade and try it out and let us know.
Comment #18
hockey2112 CreditAttribution: hockey2112 commentedI upgraded to Webform 4.x, and the tokens seem to be working perfectly. Thanks!
Comment #19
nikkubhai CreditAttribution: nikkubhai commentedDear incaic,
Thank you so much. I used the your code and it worked well except one small problem. The field value now shows
<a href="mailto:test@gmail.com">test@gmail.com</a>
while I want it just to be test@gmail.com
What should I do?
Comment #20
incaic CreditAttribution: incaic commented@nikkubhai
It does that because the default email display format is a mailto link. The code in page_node_token_field_display_alter() takes care of that, but don't forget to have it executed after the token module. I edited my post above and added the page_node_token.install file that increases the module weight to 1 which is greater than token module's default weight of 0.
Follow the following steps:
1) disable the page_node_token custom module
2) uninstall the page_node_token custom module
3) create the page_node_token.install file with the code shown above
4) enable the page_node_token module
Comment #21
nikkubhai CreditAttribution: nikkubhai commented@incaic : Sorry, but I am still facing that problem. :(
Comment #22
incaic CreditAttribution: incaic commented@nikkubhai
1) Verify the module versions I stated above (and email 7.x-1.2) are the ones you are using
2) Double check that the weight for page_node_token is set to 1 in the system table in the database. (If not, manually change it to 1 and see if that fixes it.)
3) If #2 doesn't fix it, then put some devel print messages in at email module function email_field_formatter_view() and find out which case is being executed: email_default, email_plain, etc.
Comment #23
mariusm CreditAttribution: mariusm commentedHello incaic,
I have
Drupal 7.16
Webform 7.x-4.0-alpha6
Token 7.x-1.2
Email 7.x-1.2
When I try to set
"E-mail to address " with token [page-node:field_email]
I received the error shown in the attachment :
( ! ) Fatal error: __clone method called on non-object in D:\wamp\www\testdr\sites\all\modules\page_node\page_node_token.module on line 80
Thanks,
Marius
Comment #24
mariusm CreditAttribution: mariusm commentedI solved following the instructions http://drupal.org/node/1760332
Thanks
Comment #25
mariusm CreditAttribution: mariusm commented@nikkubhai
go to
admin/structure/types/manage/YourContent/display/token
select email format "Email Plain text"
Marius
Comment #26
incaic CreditAttribution: incaic commented@mariusm, @nikkubhai
Just a quick clarification.
The instructions you point out are useful when one is sending emails to an email address set on the webform. The custom module above that creates page-node tokens are for when the email is set in the top level page node not in the webform itself.
Comment #27
sircosta CreditAttribution: sircosta commented@mariusm, finally, worked 'page-node' custom module to you? using http://drupal.org/node/1760332 instructions?
@incaic Thanks for your your custom module, nevertheless, an error appears using it:
'Fatal error (...) sites\all\modules\page_node\page_node_token.module on line 80'
Drupal 7.16
Webform 7.x-4.0-alpha6
Token 7.x-1.2
Email 7.x-1.2
As you say in your last comment, it is better not to use this custom module using http://drupal.org/node/1760332 instructions?
Comment #28
incaic CreditAttribution: incaic commented@sircosta
Provide more info on the error and I'll take a look at it.
Comment #29
sircosta CreditAttribution: sircosta commentedHi @incaic.
Just an error appears when I try to add new content (node/add/content-type) and it is:
I follow the http://drupal.org/node/1760332 instructions:
1.Create the field
2.Hide the field
3.Set the display mode to plain text ["Email plain text" in token content-type view mode]
4.-Add a new Hidden component
4.1 Label, Field Key
4.2 Default value
This is the field where you add the token to pull information from the container node. These follow the pattern:
[node:field_YOUR_FIELD_NAME] (Token module) + Here I use Page Node module and I've use [page-node:field_email] token.
4.3.- Display > Hidden Type
Using:
Drupal 7.17
Webform 7.x-4.0-alpha6
Token 7.x-1.4
Email 7.x-1.2
If you need more details, please tell me.
Thanks again.
Comment #30
Alan D. CreditAttribution: Alan D. commentedThe custom code should check the menu object
Comment #31
incaic CreditAttribution: incaic commentedAlan is correct.
Need to check whether the current page is the full page view of the passed-in node.
Comment #32
mariusm CreditAttribution: mariusm commentedHello incaic,
Please add a token for node author email like [node:author:mail]
Thanks,
Marius
Comment #33
swfindlay CreditAttribution: swfindlay commented@incaic Thank you for this module.
I can see the Page Node tokens, however, when I use them in the Webform, they don't return any values. (I've set up an email which send the Field Tokens to me on submission of the Webform).
My setup:
- Webform as block.
- My_Content_Type as the Page
- various Fields - including text
- Webform 7.x.4.x
Is there something that I am missing / doing wrong?
Thanks
Comment #34
illuminatico CreditAttribution: illuminatico commentedI'm having the same issue as @swfindlay. I have successfully gotten this to work on another site, using the same method, but now I am running into the issue where the webform is not grabbing the value for the field i have selected from the page node tokens list. At first I thought it was because of my node--mycontenttype.tpl.php page, but after completely removing it, I still can't get the value to populate.
Comment #35
illuminatico CreditAttribution: illuminatico commentedI got this working. I deleted the current form and recreated it and it worked. I have the form displaying in a block on the sidebar.
Comment #36
illuminatico CreditAttribution: illuminatico commentedI think that selecting "display all webform pages in block" as well as selecting the specific content type to display the form on helped.
Comment #37
GiorgosKone can also use http://drupal.org/project/token_custom module as I described here http://drupal.org/node/1849804 to get the node email and pass it to webform
Comment #38
swfindlay CreditAttribution: swfindlay commentedThanks @illuminatico I rebuilt the form and it now works.
Two other things I noticed when debugging:
- If the webform component is "Hidden" then under Display for that component select "Hidden Element" not "Secure Value"
- In the Tokens view for the nodetype (example.com/admin/structure/manage/[nodetype]/display/token) ensure the field is visible (i.e. not hidden), even if you don't actually want this field to be seen under the main display
Hope this helps anyone else trying to troubleshoot!
Comment #39
incaic CreditAttribution: incaic commented@swfindlay - glad it worked for you
But, not sure about your two comments:
- I am using a hidden email webform component whose value I get from [page-node:field_email] and the display hidden type I use is "Secure value".
- I don't have/use a token view mode (i.e ..../[nodetype]/display/token).
Comment #40
Terrodactyl CreditAttribution: Terrodactyl commentedThanks a lot incaic for your support.
Your module + http://drupal.org/node/1760332 got this working for me.
You made me so happy :)
Comment #41
jasom CreditAttribution: jasom commentedHi there,
token [node:author:mail] which suggested mariusm #32 is very welcome. How I can get it? It is possible to add it to you module incaic?
[node:author:mail] is a token for author of node where is webform block displayed.
Comment #42
bysv CreditAttribution: bysv commentedThank you incaic for the module in #10.
Is it possible to add a token with the author's email of the the node ([page-node:author:mail])?
I also would be interested in a token like this.
Thanks!!
Comment #43
incaic CreditAttribution: incaic commentedMake these changes to get access to the page-node author token tree.
1) Replace page_node_token_info_alter() with this one:
2) Replace page_node_token_tokens() with this one:
Comment #44
bysv CreditAttribution: bysv commentedThanks incaic!
I made these changes in page_node_token_token_info_alter() and page_node_tokens() but now the page-node tokens do not show any value. Even values [page-node: field_FIELD_NAME] now do not show any data.
I have done something wrong??
Thank you very much for your help!
Comment #45
incaic CreditAttribution: incaic commentedSorry, I made a typo. It should be page_node_token_tokens() NOT page_node_tokens() since the module name is page_node_token.
Comment #46
bysv CreditAttribution: bysv commentedPerfect incaic!
Now it works.
Thank you very much. I'll be eternally grateful
Comment #47
astuteman247 CreditAttribution: astuteman247 commented@incaic - this is a great module and works perfectly for when a user are logged in. However, I can’t seem to figure out why the fields don’t render for Anonymous users? Have you experienced this also?
Set Up
Webform as Block.
7.x-4.x
Comment #48
incaic CreditAttribution: incaic commented@astuteman247
I am only using this module for anonymous users, so I can't reproduce the problem. If you do a little debugging either with Xdebug or print statements to narrow down the problem, I might be able to help.
Comment #49
hstreitzig CreditAttribution: hstreitzig commentedGuys, you made my day.
In my case i had a content-type for jobs, displayed in panels with further information from user-profile (profile2). In a collapsible panel-region should displayed a webform for job-seekers. This form-results should be send to an e-mail-adress that user saved in the content.
I tryed so much things and days, to get this e-mail-adress as recipient - this thread was my milestone! With the changes from #43 it works perfectly!
Thanks
Comment #50
webby7097 CreditAttribution: webby7097 commentedI'm using the code above with all of the mentioned updates and modifications, and I'm not able to get at the variable I need; it doesn't show up under Page Node. I'm hoping someone can help me figure out why, or suggest an alternative.
I have email addresses as a field on a taxonomy called department, and am trying to get those addresses to attach as the 'to' field in the webform email. I can see the [page-node:field_department] as a token and it works, but I can't see the email; it shows up under [node:field-department:field_contact_email], but as it's not actually part of the webform node, it doesn't populate.
Comment #51
PascalMortier CreditAttribution: PascalMortier commentedThank you incaic ! #10 works for me !
Comment #52
olisb CreditAttribution: olisb commentedsuperb, thanks incaic. The code from #10 which I updated with #43 worked perfectly without any errors
allowing me to send a webform to the author of the node on which the webform was placed (and an admin)
which is also going to help me work a solution for webform registration (which does not seem quite ready in D7)
Many thanks for sharing this
olisb
Comment #53
maxlife58 CreditAttribution: maxlife58 commentedHi incaic yor module work very well but i've a problem, my field it's an email field created with email module and the token display the html code as
<href-my_email_field....
and i can't use it to send the webform email.
I also try to put the email _field display as plain text but it's the same!
Any help or solution?
Thanks
Comment #54
maxlife58 CreditAttribution: maxlife58 commentedSolved with #22 thanks incaic
Comment #55
incaic CreditAttribution: incaic commented@fromfriends-de, @PascalMortier, @olisb, @maxlife58 - I'm glad you got the code working and found it useful!
@webby7097 - Hope you got it working after some debugging.
Comment #56
youlikeit CreditAttribution: youlikeit commentedHi Isac
Thanks for your module. It works great for me but when submitted ad form it disabled my admin menu bar.
Any idea how to fix it? Has anyone else this problem and fixed it already??
Comment #57
millionleaves CreditAttribution: millionleaves commentedI combined the module in #10 with the replacement functions supplied in #43.
I also replaced the .info content with this - the module wasn't appearing in the module list with the code as supplied, even after removing the PHP tags:
With that done, I did the following:
This was sufficient to get the block displaying on the page, showing the email address for the node in the email field thereby demonstrating that the module worked. From there, I was able to hide the field so it wouldn't be displayed to the user, but could be used as to send an email destination after form submission.
EDIT: I found that the module I created as described here caused problems when running database updates due to the query in the .install file. I experimented with removing the .install file altogether. The module appeared to keep working, and the update error went away. In any case, the query didn't seem to have set the module weight in the system table as it's supposed to (should be 1, was still set to 0). This may the the reason some people can't get this code to work.
I'm inclined to remove the .install file altogether unless someone can suggest a fix to the query. If the module won't work for you, the Module Weight module will let you manually set the weight of the module through the GUI. It will show you the weights of all the modules in your site. If Token appears below this module on your site, then change the weight of this module so it appears below Token in the list.
Comment #58
criscomThe custom module in #10 didn't work for me as there were issues with page manager:
I had to uninstall the module and found a patch for the token module here: https://www.drupal.org/node/919760#comment-9973163
Applying that patch against the token module made node specific tokens available in my webform block: go to >> available token patterns > current page > the current node > [current-page:node:my_field]
Comment #59
jasom CreditAttribution: jasom commentedYou can send webform emails to the email field from the current node using dynamic token
[current-page:query:?]
, no special module is required anymore. This "odd" token can extract each field of the current node and insert it into the message, subject, e-mail to... For example token for the date the current node was posted will looks like:[current-page:query:?] + [node:created] = [current-page:node:created]
I wrote a tutorial here.
Comment #60
Rob T CreditAttribution: Rob T commentedThanks to MrPeanut for the direction provided in #5 and #7. I was finally able to get (parent) node information included when submitting a webform in a block.
Comment #61
christine1126 CreditAttribution: christine1126 commentedThanks Jasom (#59), it works great!
Comment #62
Maurice M. CreditAttribution: Maurice M. commentedProbably not the nicest wat to do this but it works.
Add a random emailaddress to your webform. (Not sure if this step is required).
Add the following code to your template.php hook_form_alter function.