I'm creating a new node and a new user at same time and I want to set the newly created user as author of the node. Here is what I do:
I call the node_form_alter
adds user fields to the form
adds a custom submit handler
in the submit handler i create the user
collect the new uid and try to add it to the form and formstate
load the new user
But the author is still -> Anonymous (not verified)
Im at a dead end, please help...
Here is the code
<?php
function add_user_fields(&$form)
{
$form['new_user_name'] = array(
'#title' => 'Navn',
'#description' => 'Your name',
'#type' => 'textfield',
'#required' => TRUE,
);
$form['mail'] = array(
'#title' => 'Email',
'#description' => t('Mail.'),
'#type' => 'textfield',
'#required' => TRUE,
);
// Custom submithandler for creating a user
$form['#submit'][] = 'create_task_form_player_submit_handler';
}
/*
* Implements hook_form_FORM_ID_alter()
*/
function create_task_form_player_task_node_form_alter(&$form, &$formstate)
{
if(!user_is_logged_in())
{
add_user_fields($form);
}
}
/*
* Custom submit handler
*/
function create_task_form_player_submit_handler($form, &$form_state){
$edit = array(
'name' => $form_state['values']['new_user_name'],
'pass' => user_password(4),