[support] Prepopulate contact form on node submit

Shai Gluskin shai at content2zero.com
Sun Feb 24 19:26:14 UTC 2013


Nancy, Steve, and All,

Thanks much, Nancy.

For those looking at Nancy's export, note that it requires another module
in addition to rules: workflow. So you couldn't just import that rule at
all unless the workflow module was installed.

Also note that what it is trying to do is different from what I was asking.

I've got my functionality working! Hurray, with your help!

 First let me explain that I changed my requirements after pondering the
power of the Rules module. Instead of prepopulating the contact form, Rules
sends the email on its own.

I added a field to the "resources" content type whose machine name is
field-announce-resource. It's a numeric integer list type. The two choices
I've set are:
0|No
1|Yes

In the rule, I added a condition to check to see if the value of that field
is "1". If it is, then the email goes out, if not, then it doesn't.

Here is the help text I added on the Announce field:

If you choose "Yes," an email will be sent from you and signed by you to
> listserve at example.com. It will include the title and URL of this
> resource. The email will successfully post to the listserve only if your
> account email here on example.com and your subscription email to the
> listserve are the same.
>

I had originally wanted the person posting the resource to be able to
customize the outgoing email, but I decided an email would be better.

Here is the text for the automated email, which is put in via the rules UI:

Folks,
>
> I have just posted a new resource at example.com: [node:title]
>
> Check it out at: [node:url]
>
> [node:author]
>

One thing I was very please about was setting up the from address of the
email. I used:

[node:author] <[node:author:mail]>

 which produces a well formed from Email address with the full name and
email address. (Note that on the site in question the username is always
the persons full name.) Using the Rules' "data selection" tool you can only
select one value, so you would have to use: [node:author:mail]. Using the
"direct input" method I could get the "from" field to be exactly as I
wanted it.

Rules is amazing. There is some learning curve, but it is worth it.

What follows below is my rule exported. In order to properly import on your
site (and of course you can change it using the rules UI after you've
imported it), you need to have a content type called "resource" it needs to
have a field whose machine name is "field-announce-resource" which is a
numeric field where "1" means "send the email".

Thanks everyone for all the help.

Shai


{ "rules_post_to_listserve_about_new_resource" : {
    "LABEL" : "Post to listserve about new resource",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "email", "resources" ],
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_insert" ],
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "resource" : "resource" } }
        }
      },
      { "data_is" : { "data" : [ "node:field-announce-resource" ], "value"
: "1" } }
    ],
    "DO" : [
      { "mail" : {
          "to" : "listserve at example.com",
          "subject" : "New Resource at Example.com",
          "message" : "Folks,\u000D\u000A\u000D\u000AI have just posted a
new resource at example.com called:
[node:title]\u000D\u000A\u000D\u000ACheck it out at:
[node:url]\u000D\u000A\u000D\u000A[node:author]\u000D\u000A\u000D\u000A",
          "from" : "[node:author] \u003C[node:author:mail]\u003E",
          "language" : [ "" ]
        }
      }
    ]
  }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20130224/9bf42472/attachment.html 


More information about the support mailing list