system/expressionengine/third_party/sms_custom_notification/ system/expressionengine/third_party/sms_custom_notification/ext.sms_custom_notification.php
class Sms_custom_notification_ext {
Hook | Parameters | Returns |
---|---|---|
proform_insert_end | $module, $form_obj, $data | none |
Description This hook is called just after inserting the data for the form submission into the database. This can be used to push the final data array to an external source, generating some sort of custom notification, or a number of other purposes. |
class Sms_custom_notification_ext { public $settings = array(); public $description = 'Sends an SMS notification when a form '. 'is submitted.'; public $docs_url = ''; public $name = 'SMS Custom Notification'; public $settings_exist = 'n'; public $version = '1.0'; ...
require 'Services/Twilio.php'; class Sms_custom_notification_ext { ... private $twilio_sid = 'xxxxxxxx'; private $twilio_token = 'xxxxxxxx'; private $twilio_from = '555678678'; private $twilio_notify = '111234234';
public function activate_extension() { $extensions = array( array( 'class' => __CLASS__, 'method' => 'proform_insert_end', 'hook' => 'proform_insert_end', 'settings' => serialize($this->settings), 'version' => $this->version, 'enabled' => 'y' ), ); foreach($extensions as $data) { $this->EE->db->insert('extensions', $data); } }
function proform_insert_end($module, $form_obj, $data) { // 1. Create a new Twilio API object // 2. Send the SMS // 3. We haven't change the data, but must return it: return $data; }
// 1. Create a new Twilio API object $client = new Services_Twilio($this->twilio_sid, $this->twilio_token);}
$message = $client->account->sms_messages->create( $this->twilio_from, // From Twilio number $this->twilio_notify, // To admin number <<<END New {$form_obj->form_name} post: Name: {$data['name']} Phone: {$data['phone']} Severity: {$data['severity']} END );
function proform_insert_end($module, $form_obj, $data) { // 1. Create a new Twilio API object $client = new Services_Twilio($this->twilio_sid, $this->twilio_token); // 2. Send the SMS $message = $client->account->sms_messages->create( $this->twilio_from, // From Twilio number $this->twilio_notify, // To admin number <<<END New {$form_obj->form_name} post: Name: {$data['name']} Phone: {$data['phone']} Severity: {$data['severity']} END ); // 3. We haven't change the data, but we must return it: return $data; }