I'm trying to create my first module which essentially is a visitor sign-in system where each visitor is stored as a custom content type.
The user will be a visitor to our building who's able to input their name and who they are here to see (autocomplete field based on taxonomy terms). My custom module will then add a timestamp to the node, as well as email the person they are here to see.
Code is below:
function visitor_email_staff_form_alter(&$form, &$form_state, $form_id){
if ($form_id == 'visitor_sign_in_node_form'){
$form['actions']['submit']['#submit'][0] = 'visitor_email_staff_my_custom_submit_handler';
}
}
function visitor_email_staff_my_custom_submit_handler($form, &$form_state){
$guestName = $form['field_visitors_name']['und'][0]['value']['#value'];
$staffName = $form['field_tags']['und']['#value'];
$visitorTitle = $guestName.' - '.time();
$staffTaxonomy = taxonomy_get_term_by_name($staffName);
foreach ($staffTaxonomy as $email) {
$staffEmail = $email->description; // email address
}
$form_state = array();
$form_state['values']['title'] = $visitorTitle;
$form_state['values']['field_visitors_name'] = $guestName;
$form_state['values']['field_tags'] = $staffName;
$form_state['values']['field_timestamp_in'] = time(); // timestamp
$form_state['values']['field_timestamp_out'] = '';
$form_state['values']['op'] = t('Save');
drupal_form_submit('visitor_sign_in_node_form',$form_state);
}
The major issue I'm having at the moment is getting the data to save and submit... I keep getting the below errors:
Warning: Missing argument 3 for node_form() in node_form() (line 107 of C:\www\xxx\modules\node\node.pages.inc).
Warning: Creating default object from empty value in node_form() (line 115 of C:\www\xxx\modules\node\node.pages.inc).
Notice: Undefined property: stdClass::$type in node_object_prepare() (line 981 of C:\www\xxx\modules\node\node.module).
Notice: Undefined property: stdClass::$type in _node_extract_type() (line 379 of C:\www\xxx\modules\node\node.module).
Notice: Undefined property: stdClass::$type in comment_node_prepare() (line 1298 of C:\www\xxx\modules\comment\comment.module).
Notice: Undefined property: stdClass::$type in menu_node_prepare() (line 568 of C:\www\xxx\modules\menu\menu.module).
Notice: Undefined property: stdClass::$type in _node_extract_type() (line 379 of C:\www\xxx\modules\node\node.module).
Notice: Undefined property: stdClass::$type in node_form() (line 294 of C:\www\xxx\modules\node\node.pages.inc).
Notice: Undefined property: stdClass::$type in node_form() (line 300 of C:\www\xxx\modules\node\node.pages.inc).
Notice: Undefined property: stdClass::$type in node_form() (line 321 of C:\www\xxx\modules\node\node.pages.inc).
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7922 of C:\www\xxx\includes\common.inc).
Am I going about this the wrong way? Should I be using something else instead of drupal_form_submit()
?
$form['actions']['submit']['#submit'][0]
use$form['actions']['submit']['#submit'][]
instead.