Jump to:

3462 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [SOLVED] Calling an email template function using a button

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

Page: 1
Go to End
Author Topic: 1109 Views
  • cumquat
    Avatar
    Community Member
    198 Posts

    [SOLVED] Calling an email template function using a button Link to this post

    Hi there,

    I've been looking around the forum all day and so far i haven't been able to come up with a solution, i want to have a button on the screen that when clicked runs a function that is set to email instructions to an email group, i have most of it done but i don't seem to be able to make a button run the function. My code is below, as ever would welcome some pointers or even the answer :o)

    function EmailSearchTeam() {
          return new Form($this, '', new FieldSet(new HiddenField('Hidden')), new FieldSet(new FormAction('doEmailSearchTeam', 'Email the Team')));
       }
          
       function doEmailSearchTeam() {
       
       $email = new Email();
    $email->setTemplate('TestEmail');
        $email->setFrom('xxxx@xxxxx.com');
    $email->setTo('yyyyyy@yyyyyy.com');
    $email->setSubject('New Event Added ');
    $email->populateTemplate(Member::currentUser());
    $email->populateTemplate(array(
           'Title' => $this->owner->Title,
           'Date' => $this->owner->StartDate,
           'StartTime' => $this->owner->StartTime,
       'Location' => $this->owner->Location,
          'Contact1' => $this->owner->Contact1,
    ));
    $email->send();
    }

    Sorry should add, there are no errors it all looks like it works but no email is sent, i'm wondering whether you can actually call a function like this.
    Hope someone can help.

    regards

    Mick

  • cumquat
    Avatar
    Community Member
    198 Posts

    Re: [SOLVED] Calling an email template function using a button Link to this post

    Well still trying to get this idea run, the email gets sent if i attach it to the onAfterWrite() function so i think the email code is fine, i just don't think the function is being called from the form button.

    Is what i'm trying to do possible?

    Mick

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: [SOLVED] Calling an email template function using a button Link to this post

    You're missing the 2 parameters in your doEmailSearchTeam function for the form handler to match. I think you need to change it too doEmailSearchTeam($data, $form)

  • cumquat
    Avatar
    Community Member
    198 Posts

    Re: [SOLVED] Calling an email template function using a button Link to this post

    Hi Willr,

    Thanks for getting back, I've had those parameters in and out to no avail. It just doesn't seem to want call that function.

    Mick

  • Willr
    Avatar
    Forum Moderator
    5511 Posts

    Re: [SOLVED] Calling an email template function using a button Link to this post

    Could you post that whole file? FYI the form and action need to be in a controller (not a dataobject) so that it can be posted to it after the form submits.

  • cumquat
    Avatar
    Community Member
    198 Posts

    Re: [SOLVED] Calling an email template function using a button Link to this post

    Hi ya,

    I thought that was gonna be it, i was hoping that was gonna be it but alas it is on a controller, it's actually on UC's calendar.php file as i'm tweaking that so those two functions are added to the bottom of that.

    I may have a work around i'm gonna try which will add functionality anyway which is to create a new table and write to that with a log of email sent then use the email function on the onAfterWrite() function to send it.

    Cheers and Happy Easter.

    Mick

  • cumquat
    Avatar
    Community Member
    198 Posts

    Re: [SOLVED] Calling an email template function using a button Link to this post

    Ok i have now got this part sussed, it was because of the static $allowed_actions = array which was on the page, i hadn't added my function to that list.

    DOH!!!

    ok now onto the next part which is to actually get the data.

    regards

    Mick

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