2017 © Pedro Peláez
 

silverstripe-module emailing-form

This module bundles the emailing process into a form object. It also supports the routing of emails to a test address.

image

silverstripe/emailing-form

This module bundles the emailing process into a form object. It also supports the routing of emails to a test address.

  • Thursday, April 2, 2015
  • by dangerdan
  • Repository
  • 1 Watchers
  • 1 Stars
  • 764 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 3 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Silverstripe emailing form

This module bundles the emailing process into a form object. It also lets you route emails to a test address for manual testing of an email form., (*1)

Usage

Build the form as usual, but with EmailingForm::create() instead of Form::create(). EmailingForm exposes setting up the email via the form object., (*2)

public function ContactForm() {

    // ...

    $form = EmailingForm::create(
        $this, 'ContactForm', $fields, $actions
    );

    $form->setTo('recipient@gmail.com');
    $form->setFrom('Me <sender@gmail.com>');
    $form->setSubject('Hello');
    $form->setEmailTemplate('ContactFormEmail');

    return $form;
}

Then in the form action simply do:, (*3)

public function SendForm($data, $form){
    $form->Send($data);
}

The Send method will automatically sanitize the data for you before loading it into the template., (*4)

Test conditions

This module can be configured to route test emails to a test address for manual form testing. In your main project, configure the EmailTools object in your _config.php:, (*5)

EmailTools::setTestRouteAddress('emailtest@yourdomain.co.uk');
EmailTools::setTestData(array('emailtest@yourdomain.co.uk'));

Then when you're setting up the form as shown in the usage example do:, (*6)

$form->setTestCondition(function($e, $data)
{
    return EmailTools::isTestData($data['Email']);
});

The module passes the submitted $data to this callback, if it is set. In this example, we're checking the input data 'Email', however you can check any field you like. If this callback returns true, EmailingForm will route your email to your test address., (*7)

The Versions

02/04 2015

dev-master

9999999-dev

This module bundles the emailing process into a form object. It also supports the routing of emails to a test address.

  Sources   Download

The Requires

 

by Dan Brooks

email silverstripe