Hello If member publish entry I want publish some info to another channel I wrote extension, but it doesn’t work and always I see ‘An Error Occurred Creating the Entry’ I need help
This is my code
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Calladder_ext {
public $name = 'Call adder';
public $version = '1.0';
public $description = 'Add call when publish to channel';
public $settings_exist = 'n';
public $docs_url = '';
private $settings = array();
/**
* Constructor
*
*/
public function __construct($settings='')
{
$this->EE =& get_instance();
$this->EE->lang->loadfile('calladder');
}
public function add_call($entry_id, $meta, $data)
{
if( in_array( $data['channel_id'], array(4,5,6) ) )
{
//prepare data
// some code...
$datap = array(
'title' => $title,
'entry_date' => $this->EE->localize->now,
'channel_id' => 7,
'field_id_48' => $phone,
'field_id_47' => $name,
'field_id_50' => $email,
'field_id_49' => $comment,
'field_id_88' => $entry_id
);
$this->insert_entry(7, $datap);
}
}
private function insert_entry($channel_id, $data)
{
$this->EE->load->library('api');
$this->EE->api->instantiate('channel_entries');
$this->EE->api->instantiate('channel_fields');
$this->EE->api_channel_fields->setup_entry_settings($channel_id, $data);
if ($this->EE->api_channel_entries->submit_new_entry($channel_id, $data) === FALSE)
{
show_error('An Error Occurred Creating the Entry');
}
}
public function activate_extension()
{
$data = array(
'class' => __CLASS__,
'method' => 'add_call',
'hook' => 'entry_submission_end',
'settings' => serialize($this->settings),
'priority' => 2,
'version' => $this->version,
'enabled' => 'y'
);
$this->EE->db->insert('extensions', $data);
}
public function disable_extension()
{
$this->EE->db->where('class', __CLASS__);
$this->EE->db->delete('extensions');
}
}
?>Hi Maxim,
You will need to pass the entry_date with $data
$datap = array(
'title' => $title,
'channel_id' => 7,
'entry_date' => $this->EE->localize->now,
'field_id_48' => $phone,
'field_id_47' => $name,
'field_id_50' => $email,
'field_id_49' => $comment,
'field_id_88' => $entry_id
);Also, check if the current logged in member having the privilege to post/update entry within that channel.
Best Regards,
Hi Maxim,
I have used channel entry api in number of times but didn’t face such a problem. Could you check if any custom field is required for that channel and you are not using within $datap array.
Also try by having author_id within $datap array. May be it can solve your issue.
Best Regards,
I just added url_title, but I don’t need generate url_title:
$datap = array(
'title' => $title,
'url_title' => 'contact',
'entry_date' => $this->EE->localize->now,
'channel_id' => 7,
'field_id_48' => $phone,
'field_id_47' => $fio,
'field_id_50' => $email,
'field_id_49' => $comment,
'field_id_88' => $entry_id
);Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.