Blog
ProForm Extensions - Sending an SMS Notification
February 26, 2012
Tags: extensions, proform, ee, add-on development, twilio
ProForm has an extensive list of available hooks with which you can extend it's behavior by writing fairly simple custom extensions. You can find a complete list and description of each hook on the ProForm Extension documentation page.
In this post, I'm going to walk you through a simple custom notification extension for ProForm, built using one of these hooks.
Let's say you want to send an SMS notification out to a service technician when a particular form is filled out on your site. With ProForm, we can easily accomplish this using the Twilio API and a simple custom extension.
Create the ExtensionIf you want to follow along, create a new blank extension using the ExpressionEngine package builder pkg.io. I'll also include the complete source code at the end of this post.
I'll be using the name Sms_custom_notification_ext for this example extension. pkg.io will create a file named ext.sms_custom_notification.php for the extension, according to the ExpressionEngine conventions.
Register the HookOpen the ext.sms_custom_notification.php file and add the following code to register the proform_insert_end hook in the extension:
File: ext.sms_custom_notification.php
<?php // Snippet:
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);
}
}
Here's the documentation for the hook that we're using:
HookParamsReturn proform_insert_end $module, $form_obj, $data noneDescription
This hook is called just after inserting the data...
Easy custom plugins
January 11, 2012
Tags: ee, add-on development, plugins
Edit: I've recently (1/17/2011) given a short talk on this at the @TwinCitiesEE user group. Slides from that talk are here. Read on for more detailed discussion of the topic.
Imagine a scenario where you have some special data that you wish to query out of either built in ExpressionEngine tables or out of custom tables added by a third-party package.
Usually what most people would do at this point is resort to using the query plugin to obtain data from a custom query. However, I want to show you a better way to achieve the same kind of access to data in internal tables, but in a much safer and more controllable way.
First a little about why the query plugin isn't such a great idea in this situation. Generally, when we need to query tables in a MySQL database, we need to pass in some information that we have been given by the user or at least which has passed through the user's machine in the form of a link in a URL segment, or in a value posted to a form. For instance, you may want to get some custom member information based on a member ID. You could do this using the Query plugin like in the following example.
Imagine we have a template group named account and a template named member_info which performs this custom query. The root URL of our example site site is http://www.example.com/.
URL: http://www.example.com/account/member_info/45
Template: account/member_info
<h2>Member Info</h2>
{exp:query sql="SELECT * FROM exp_members WHERE member_id={segment_3}"}
Screen Name: {screen_name}<br/>
Registered Email Address: {email}<br/>
Username: {username}<br/>
<a href="{...