We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28590
    • 6 Posts
    I have implemented "Send to Friend" feature using eForm. The steps are:

    1. implement referer snippet:

    <?php
    return $_SERVER['HTTP_REFERER'];
    ?>
    


    2. create a page which will host "send to friend" form, for example a page with alias "share"

    Please enter details about you and your friend
    
    [!eForm? &formid=`shareForm` &tpl=`share-form` &report=`share-report` &thankyou=`share-thankyou`  &from=`[email protected]` &sendirect=1 &subject=`[+yourName+] recommends you a page`!]


    Note the sendirect argument, we will come back to it later.

    Now you have to define three chunks: share-form, share-report and share-thankyou.

    3. create a form share-form

    [+validationmessage+]
    <form class="askform" method="post" action="[~[*id*]~]">
        <input type="hidden" name="formid" value="shareForm" />
        <input type="hidden" name="referer" value="[[referer]]" eform="::0::"/>
        
        <p><label accesskey="e" for="email">Friend's Email Address</label>
        <input type="text" name="email" size="40" maxlength="60" eform="Friend's Email Address:email:1" /></p>
        
        <p><label accesskey="n" for="yourName">Your Name</label>
        <input type="text" name="yourName" maxlength="60" eform="Your Name::1:" /></p>
    
        <p><label accesskey="e" for="youremail">Your Email Address</label>
        <input type="text" name="youremail" size="40" maxlength="60" eform="Your Email Address:email:0" /></p>
    
        <p><label accesskey="c" for="comments">Comments</label>
        <textarea cols="40" rows="10" name="comments" eform="comments:html:1"></textarea></p>
    
        <p><input class="submit" type="submit" name="submit" value="Share"></p>
    </form>
    


    It is important to have the friends email identified as email, it will be used as recipient of the message by using the previously mentioned flag sendirect=1.

    4. Create mail message body chunk named share-report

    In the message you are going to use
    [+referer+]
    as a link to the page the visitor was visiting just before he decided to share the page:

     <p>Hi,</p>
    <p>
    Your friend [+yourName+] [+youremail+] would like you to see a page at YOUR_SITE_NAME web site. He notes:</p>
    <p>[+comments+]</p>
    <p>The link to the page is: <a href="[+referer+]">[+referer+]</a></p>
    
    <p>We hope that you will find the link useful.</p>
    <p><em>Note: This is automated email message. Please, do not reply to this email. </em></p>
    <p>Best regards,</p>
    


    5. Create a thank you message chunk share-thankyou

    6. Put a link to the "share" page in a page template

    I think it is all. Enjoy.
      • 7231
      • 4,205 Posts
      Nice tutorial. I would normally use modx parameters to build the link so that I could add the page title and personalize it a bit. But both methods will work.

      Or you could just change this line to include the pagetitle:
      <p>The link to the page is: <a href="[+referer+]">[+pagetitle+]</a></p>

      or build the link with modx parameters:
      <p>The link to the page is: <a href="[(site_url)][~[+id+]~]">[+pagetitle+]</a></p>


      Maybe your tutorial should be in the wiki grin
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don&#39;t know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 28590
        • 6 Posts
        How would you get page title, page id and other modx stuff of a page that you have visited before? I wanted to do that but did not figured out how. Note that described solution calls another page with the form - the form is not on the page which is going to be recommended. pagetitle and id in the forms are going to be of the "Share with friend" page, not of the recommended page.

        Perhaps some ajax based pop-up form on the same page would be nicer...but I am expert in that area.
          • 25483
          • 741 Posts
          Quote from: Stiivi at Nov 10, 2008, 10:52 AM

          How would you get page title, page id and other modx stuff of a page that you have visited before? I wanted to do that but did not figured out how. Note that described solution calls another page with the form - the form is not on the page which is going to be recommended. pagetitle and id in the forms are going to be of the "Share with friend" page, not of the recommended page.

          Perhaps some ajax based pop-up form on the same page would be nicer...but I am expert in that area.

          I did this by putting the form on the page and don’t display it with css. Then I have a link you click on which activates the form so that you see it.
          I used it on http://www.rotako.nl/engineering.html . Try click on the "Stuur door" button and see what happens wink
            with regards,

            Ronald Lokers
            'Front-end developer' @ h2o Media

            • 7231
            • 4,205 Posts
            How would you get page title, page id and other modx stuff of a page that you have visited before?
            Oh, I figured it was on the same page (duhh, why else would you use referrer, i can’t answer posts before coffee). To do this I would pass the referring page ID in the url and use it with the modx api (or the getfield snippet) to get the pagetitle.
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]
            • I know this is an old topic but I need a little help for the referer part.

              <?php
              return $_SERVER['HTTP_REFERER'];
              ?>


              seems to work if signed in as the manager... it shows the correct page url but if I am not signed in as the manager, the referer is blank. How can I get this working for webusers?
                Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
                AugmentBLU - MODX Partner

                BLUcart - MODX Revolution E-Commerce & Shopping Cart