I have built an extension using the freeform_module_insert_end hook according to Solspace Extensions documentation as I want the form to redirect to a custom url including a unique hash - but for some reason I cannot get the hook to fire. I have pasted the code below:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Freeform Redirect Extension class
*
* @package freeform_redirect
*/
class Freeform_redirect_ext {
var $name = 'Freeform Redirect';
var $version = '1.0.0';
var $description = 'Redirect to custom url';
var $settings_exist = 'n';
var $docs_url = '';
var $settings = array();
/**
* Constructor
*
* @param mixed Settings array or empty string if none exist.
*/
function __construct($settings = '')
{
$this->settings = $settings;
}
/**
* Activate Extension
*
* This function enters the extension into the exp_extensions table
*
* @see https://ellislab.com/codeigniter/user-guide/database/index.html for
* more information on the db class.
*
* @return void
*/
function activate_extension()
{
$this->settings = array(
'max_link_length' => 18,
'truncate_cp_links' => 'no',
'use_in_forum' => 'no'
);
$data = array(
'class' => __CLASS__,
'hook' => 'freeform_module_insert_end',
'settings' => serialize($this->settings),
'priority' => 10,
'version' => $this->version,
'enabled' => 'y'
);
ee()->db->insert('extensions', $data);
}
/**
* Disable Extension
*
* This method removes information from the exp_extensions table
*
* @return void
*/
function disable_extension()
{
ee()->db->where('class', __CLASS__);
ee()->db->delete('extensions');
}
public function freeform_module_insert_end($inputs, $entry_id, $form_id, $obj)
{
if ( ! $obj->edit AND
( ! $obj->multipage OR
($obj->multipage AND $obj->last_page)
)
)
{
$obj->params['return'] = 'thank-you/'.ee()->input->post('unique_hash');
}
}
// --------------------------------------------------------------------
} // End Class Freeform_redirect_ext
/* End of file ext.freeform_redirect.php */