I am using auto node title which will generate the title of a node. However, this is not happening when I create a node using node_save. See below:
function save_contact($firstName, $lastName, $email, $showErrors = false) {
global $user;
$edit = array();
$edit['type'] = 'contact';
$edit['uid'] = $user->uid;
$edit['name'] = $user->name;
$edit['promote'] = 0;
$edit['comment'] = 0;
$edit['status'] = 1;
$edit['field_contact_name'][0]['value'] = $firstName; // NOTE
$edit['field_contact_surname'][0]['value'] = $lastName; // NOTE
$edit['field_contact_email'][0]['email'] = $email; // NOTE
$edit['title'] = $firstName.' '.$lastName; // NOTE
node_invoke_nodeapi($edit, 'contact');
node_validate($edit);
$node = node_submit($edit);
node_save($node);
}
save_contact("NAME", "SURNAME", "me@bla.com");
When the node is generated, the title becomes: “[field_contact_name-formatted] [field_contact_surname-formatted] ” instead of, “NAME SURNAME”.
Any idea why? I’m guessing auto node title is not picking up that I’ve entered values, or that maybe the title generation happens before the point in time where I specify the values.
Any ideas?
I fixed it like so:
In other words, I had to also specifiy the safe and view fields.