I’ve read a few posts on this, and for the life of me I can’t get this working. I want to intercept a Channel Form submission, and modify the submitted data.
I’m using the ‘entry_submission_ready’ extension hook, which fires fine. I can access the $data array, but I cannot modify an element so that it is saved when the entry is saved.
I’m accessing the $data arary by reference ( &$data ), but that doesn’t make any difference.
Where an I going wrong?
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* ExpressionEngine - by EllisLab
*
* @package ExpressionEngine
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2003 - 2011, EllisLab, Inc.
* @license http://expressionengine.com/user_guide/license.html
* @link http://expressionengine.com
* @since Version 2.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* Contact Notify Extension
*
* @package ExpressionEngine
* @subpackage Addons
* @category Extension
* @author James Seavers
* @link http://www.symphonyonline.co.uk
*/
class Contact_notify_ext {
public $settings = array();
public $description = 'Notifies when an entry is created in contact request channel after changing some data';
public $docs_url = '';
public $name = 'Contact Notify';
public $settings_exist = 'n';
public $version = '1.0';
private $EE;
private $recipient = '[email protected]';
/**
* Constructor
*
* @param mixed Settings array or empty string if none exist.
*/
public function __construct($settings = '')
{
$this->EE =& get_instance();
$this->settings = $settings;
}// ----------------------------------------------------------------------
/**
* Activate Extension
*
* This function enters the extension into the exp_extensions table
*
* @see http://codeigniter.com/user_guide/database/index.html for
* more information on the db class.
*
* @return void
*/
public function activate_extension()
{
// Setup custom settings in this array.
$this->settings = array();
$data = array(
'class' => __CLASS__,
'method' => 'change_data',
'hook' => 'entry_submission_ready',
'settings' => serialize($this->settings),
'version' => $this->version,
'enabled' => 'y'
);
$this->EE->db->insert('extensions', $data);
}
// ----------------------------------------------------------------------
/**
* change_data
*
* @param
* @return
*/
public function change_data($meta, &$data, $autosave=false)
{
$data['field_id_60'] = 'test';
}
}
Thanks in advance, James