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

Channel Entries API enforcing required custom fields from irrelevant channels

Development and Programming

ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

I’m trying to use the Channel Entries API to programmatically create some entries and seem to have run into a bug.

I’m attempting to insert entries into channel #5 (Counties). It has one custom field (#17).

There are two custom fields in the EE installation that are required: “Summary” from channel #4 and “City” from channel #6.

My code looks like this:

$data = array(
    'title' => 'some title',
    'channel_id' => 5, // necessary because of other bug that is marked fixed for next release
    'entry_date' => '2010-09-10 01:40 PM',
    'field_ft_17' => 'xhtml',
    'field_id_17' => 'whatever'
);

if ($this->EE->api_channel_entries->submit_new_entry(5, $data) === FALSE)
{
    show_error('An Error Occurred Creating the Entry');
}

A print_r of the errors set by the API looks like this:

Array ( 
    [Summary] => The following field is required: 
    [City] => The following field is required: 
)

The culprit appears to be the following code in Api_channel_entries.php, function _check_for_data_errors, roughly line 1125:

// Required and custom fields
        
$this->EE->db->select('field_id, field_label, field_type, field_required');
$query = $this->EE->db->get('channel_fields');

Seems like the solution would be to filter that database select on the current channel’s assigned field group.

Moved to Development and Programming by Moderator

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
15 years ago
Sue Crocker's avatar Sue Crocker

Hi, Ty. This sort of question is more appropriate for the Developer forum. Moving there for additional community support.

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
15 years ago
Rob Sanchez's avatar Rob Sanchez

I noticed this, too, the other day. Curious that the field_model wasn’t used here.

       

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.