Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » "Tip a friend" form.

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 2185 Views
  • Siv
    Avatar
    Community Member
    6 Posts

    "Tip a friend" form. Link to this post

    Have anyone made "tip a friend" form?

    The problem is how to send page link or something else to an email adress that comes from a form that user has been filled out on a website - and automatically send the link to that pages the form are on - to the email adress owners email account?

    Any tip?

    Have a beautyful day

  • Martin Pales
    Avatar
    Community Member
    19 Posts

    Re: "Tip a friend" form. Link to this post

    I am about to work on the same feature. My first idea is to use a custom form validation. I appreciate any help though.

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: "Tip a friend" form. Link to this post

    You an do this by creating a custom pagetype,

    Just create a new page type, then add the form to that (you can do all the validations there), then on the controller make use of the Email class to send emails,

    Use this as a reference

    http://doc.silverstripe.com/doku.php?id=Form

  • Siv
    Avatar
    Community Member
    6 Posts

    Re: "Tip a friend" form. Link to this post

    Hello fra Norway!

    Here is a code for page.php, but the variable/method for catching the pages URL is missing.

    Any tip?

    The vairable "$TipFriendFrom" must be in the l .ss file where the form shall be placed. I could'nt see anything in the api link over to help us there.

    Here is the page.php code:

    <?php

    class Page extends SiteTree {
    static $db = array(
    );
    static $has_one = array(
    );

    function TipFriendForm() {
    $fields = new FieldSet(
    new TextField(
    $name = "Name",
    $title = "Ditt navn: "
    ),
    new EmailField("Email", "E-post adresse: "),
    new HiddenField("Side", $db->URL)
    );
    $validator = new RequiredFields("Email");
    $actions = new FieldSet(new FormAction("tipFriend", "Send tips"));
    return new Form($this, "TipFriendForm", $fields, $actions, $validator);
    }
    }

    class Page_Controller extends ContentController {
    function init() {
    parent::init();

    Requirements::themedCSS("layout");
    Requirements::themedCSS("typography");
    Requirements::themedCSS("form");
    }

    function tipFriend ($data, $form) {

    $from = "system@w3spor.no";
    $subject = "Tips fra din venn";
    $to = $data["Email"];
    $body = $data["Name"] . " har sendt deg følgende link tips: \n" . $data["Side"];

    $email = new Email($from, $to, $subject, $body);
    $email->send();

    Director::redirectBack();

    }
    }

    ?>

  • justjc51
    Avatar
    Community Member
    23 Posts

    Re: "Tip a friend" form. Link to this post

    You could also take a look at the Sharethis module http://doc.silverstripe.com/doku.php?id=modules:sharethis I've used it to great effect in my attempts to make the option to send a message to a friend through e-mail or facebook

    2185 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.