We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Publish in 2 channels

Development and Programming

Maxim WEB's avatar
Maxim WEB
18 posts
13 years ago
Maxim WEB's avatar Maxim WEB

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');
 }
}
?>
       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

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,

       
Maxim WEB's avatar
Maxim WEB
18 posts
13 years ago
Maxim WEB's avatar Maxim WEB

entry_date isn’t required and I post from admin

       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

Could you confirm if you tried by having entry_date?

Best Regards,

       
Maxim WEB's avatar
Maxim WEB
18 posts
13 years ago
Maxim WEB's avatar Maxim WEB

Yes. Now I have tried with entry_date and this don’t solve my problem I updated my code in my first message

       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

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,

       
Maxim WEB's avatar
Maxim WEB
18 posts
13 years ago
Maxim WEB's avatar Maxim WEB

Entry is not created because url_title can not be created Maybe it is a bug because I work with russian language This code help me find the error:

var_dump($this->EE->api_channel_entries->errors); exit();
       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

Maxim,

Can you please share what error you get and how did you resolve it? it would be a pointer for someone facing same issue in future.

Best Regards,

       
Maxim WEB's avatar
Maxim WEB
18 posts
13 years ago
Maxim WEB's avatar Maxim WEB

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
            );
       
Maxim WEB's avatar
Maxim WEB
18 posts
13 years ago
Maxim WEB's avatar Maxim WEB

And how I can add category?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.