How to send current page title or url in email using dynamic forms?

Topics: Core, Customizing Orchard, General
Feb 27 at 9:49 AM
I have Contact Us form on every page.
So I have to know from what page exactly the form was send and I try to get page tite or url using tokens but still can't do it.
I'm new in using Orchard. May be someone can help me. Thanks!
Mar 2 at 8:21 PM
Edited Mar 2 at 8:32 PM
I asked a similar question on Orchard Pros. See: Determine Page Referring to Dynamic Form.

You have to enable the Elements.Token feature.

Here is how I accomplished this:
  • STEP 1: In the Content Item itself (i.e., the "Welcome to Orchard" page), using Orchard.Layouts and the HTML Element, insert ?referrer=#{Content.DisplayText} at the end of the URL link. This is the page that is referring to another page.
    • e.g.: <a href="TestForm?referrer=#{Content.DisplayText}">Test Form</a>
    • Alternative: <a href="TestForm?referrer=#{Content.DisplayUrl}>Test Form</a>
      • This displays the URL rather than the TITLE of the page (your choice).
    • Note: If the HTML Element is in a Widget that is attached to a Content Item then it becomes: ?referrer=#{Request.Content.DisplayText}
    • The full name of the Content Item is what will be output to the e-mail sent to the user.
    • Note: If the HTML anchor is in a Themed .cshtml file, insert the actual page as the referrer: <a href="TestForm?referrer=/Solutions/Bankruptcy/Chapter7">Test Form</a>
  • STEP 2: Create a Dynamic Form and add a Text Field and insert {Request.QueryString:referrer} in the "Value" text box for the Text Field properties.
    • Note: The "Name" Field should probably not contain spaces (e.g.., "TestTextField" not "Test Text Field").
      • This is for convention purposes, as I think with jQuery you cannot access a field with spaces (at least with HTML ID's). I could be wrong on that.
  • STEP 2.A: In the Text Field's "Field Properties" (on the Layout itself), add Display:none; to the CSS styles.
  • STEP 3: Create a standard workflow with "Dynamic Form Validating", "Dynamic Form Submitted" and "Send E-Mail" Activities.
  • STEP3.A: In the Send E-Mail Activity input the following #{Request.Form:TestTextField} somewhere in the activity:
    • Note: The "TestTextField" name must match the Text Field name input in Orchard.Layouts/DynamicForms
    • e.g.:
          <p>Name of Content Item: #{Content.DisplayText}</p>
          <p>Name of Field which uses a Token to pass the name: #{Request.Form:TestTextField}<p>
This will output:
Name of Content Item: Test Form
Name of Field which uses a Token to pass the name: Welcome to Orchard!
I got this from the link above at Orchard Pros. BTW, they are very active there (at least last that I checked a few months ago). I hope it helps.