Hello,
what is the correct way to reference event start and end time, when using drupal_execute() to create a node programmatically?

Here is the code I am using

$form_state['values']['start'] = '2008-04-26T13:00:00';	
$form_state['values']['end'] = '2008-04-26T13:00:00';

Node gets created OK, but time is set to some default value. I most likely refer to it incorrectly.

Thank you.

Comments

killes@www.drop.org’s picture

try replacing the "T" with a blank " ".

dostoevsky’s picture

didn't work.
i'm trying different combinations.

gerhard killesreiter’s picture

I've rewritten the form layer for the event module.

As a result

$form_state['values']['start_exploded'] = array('year' => '2008', 'month' => '04', 'day' => '26', 'hour' => '13' 'minute' => '00' );

should work.

vegeneric’s picture

this took me a while to figure out, because anything less than the perfect code here seems to get you very strange results. here's a working snippet for creating events programmatically, in case others run into difficulties:

$form_state = array(); 
module_load_include('inc', 'node', 'node.pages');
$node = array('type' => 'event'); 
$form_state['values']['title'] = 'My node'; 
$form_state['values']['body'] = 'This is the body text!'; 
$form_state['values']['name'] = 'admin'; 
$form_state['values']['op'] = t('Save'); 
$form_state['values']['event']['start_exploded'] = array('year' => '2009', 'month' => '04', 'day' => '26');
$form_state['values']['event']['has_time'] = 1;
$form_state['values']['event']['has_end_date'] = 0;
$form_state['values']['event']['timezone'] = variable_get('date_default_timezone_id', 0);

drupal_execute('event_node_form', $form_state, (object)$node);

i was stuck for a while because i tried to write the events section as one array, like this:

$form_values['values']['event'] = array(
	'start_exploded' => array('year' => '2008', 'month' => '04', 'day' => '26'),
	'has_time' => 0,
	'has_end_date' => 0,
	'timezone' => variable_get('date_default_timezone_id', 0),
);

which kept returning me the obnoxiously vague 'illegal choice detected, please contact a site admin' message. anyway, hope this helps someone!

dostoevsky’s picture

Status: Active » Closed (fixed)