Speaking of that fun little bit of code, <a href="http://drupal.org/node/683630">http://drupal.org/node/683630</a> is a D7 patch I just submitted to remove the hard-coded 'administer users' check and clean up that logic in node_submit(). It could use a review or two. :)<br>
<br clear="all">Dave Reid<br><a href="mailto:dave@davereid.net">dave@davereid.net</a><br>
<br><br><div class="gmail_quote">On Wed, Jan 13, 2010 at 9:46 AM, Brian Vuyk <span dir="ltr"><<a href="mailto:brian@brianvuyk.com">brian@brianvuyk.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Just to follow up on the original post...<br>
<br>
The reason this wouldn't save is because of this little code block in node_submit() which is called by the node_form_submit() submit handler, which executes after my custom submit handler:<br>
<br>
if ($account = user_load(array('name' => $node->name))) {<br>
$node->uid = $account->uid;<br>
}<br>
<br>
Setting $form_state['values']['name'] to the new account's name caused the right uid to be assigned.<br>
<br>
Thanks for the responses and suggestions, all of you!<br><font color="#888888">
<br>
Brian</font><div><div></div><div class="h5"><br>
<br>
On 10-01-12 04:24 PM, Brian Vuyk wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all.<br>
<br>
I've been trying to get a bit of code working, and I would appreciate a set of eyes.<br>
<br>
Basically, I have a content type ('profile') which has fields for user account details. If they are filled out, and a 'Create account' checkbox is checked, a user account is created with those details, and the profile node should be assigned to the newly-created user instead of the user creating the node.<br>
<br>
The issue is that, while the new user is created properly in the submit hook, the last line in the submit callback where I override the 'uid' value from the form values doesn't work - the node just saves with the user's uid instead of the uid of the new account that is specified on the last line.<br>
<br>
Does anyone have any idea how to make this work?<br>
<br>
Thank you in advance for anyone that can suggest a solution!<br>
<br>
Brian<br>
<br>
<?php<br>
function mymodule_form_profile_node_form_alter(&$form, &$form_state) {<br>
// Add our submit handler. We use array_unshift to prepend it, as we want it<br>
// to execute before the regular node form submit handler.<br>
array_unshift($form['buttons']['submit']['#submit'], 'mymodule_profile_form_submit');<br>
}<br>
<br>
// Submit the user account creation fields in the profile_node_form.<br>
function mymodule_profile_form_submit($form, &$form_state) {<br>
<br>
// Create the user account.<br>
if ($form_state['values']['create']) {<br>
$account['name'] = $form_state['values']['username'];<br>
$account['mail'] = $form_state['values']['mail'];<br>
$account['pass'] = $form_state['values']['pass'];<br>
$account['status'] = 1;<br>
$account = user_save(array(), $account);<br>
<br>
// Now set the uid of the profile node to be owned by this new account.<br>
$form_state['values']['uid'] = $account->uid;<br>
}<br>
}<br>
?><br>
</blockquote>
<br>
</div></div></blockquote></div><br>