Jump to:

10990 Posts in 2727 Topics by 1818 members

All other Modules

SilverStripe Forums » All other Modules » UserForms: sending custom messages incl. variables

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1647 Views
  • Martiman
    Avatar
    Community Member
    7 Posts

    UserForms: sending custom messages incl. variables Link to this post

    Hi,

    We're searching for a method to send custom messages after filling in a form, using the fields of the form in the message (for example, tell-a-friend messages).

    Currently there seems to be no way of doing this with UserForms. It is possible to make a custom message in the tab "Email Recipients", but there is no way to use the information from the form itself. I would like to see some way to use the fields in messages like this:

    "Dear $NameTo,
    foo foo foo
    Chears,
    $NameFrom ($EmailFrom)"

    It would be nice to get a checkbox too where you can define whether or not you want to get the whole form content glued beneath the body.

    Will it be possible to implement such a function in one of the next releases? Are there some other ideas to get this functionality until the UserForms module supports this?

    Thnx!

  • novaweb
    Avatar
    Community Member
    115 Posts

    Re: UserForms: sending custom messages incl. variables Link to this post

    Hi Martiman,

    This is easy to do if you code the form yourself.

    Basically - create a new page type for your form:

    MyFormPage.php

    and in MyFormPage_Controller() {

    you should define a form function:

    function Form() {

    Go here for details on the form function
    http://doc.silverstripe.org/recipes:forms
    http://doc.silverstripe.org/form

    }

    In your submit function, all your form variables will be available to send in the email in the following way:

    $data["FirstName"]
    $data["Email"] etc

    So in the form function you could do something like the following:

       function submit($data, $form) {
       
       $form->makeReadonly();
       $email = new Email;
       $email->to = 'you@you.com';
       $email->from = 'referral@mywebsite.com';
       $email->subject = 'New Referral';
       $email->body = "Hi,<br /><br />There has been a blah blah blah from " . $data['FirstName'] . " " . $data['LastName'] . " through the website!";
       $email->send();

       // Redirect
       

          Director::redirect('finish-page);

       
       }
       
    }

    // This code may not be perfect I had to cut a lot of sensitive data out!!!

    Josh

    1647 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.