if you need to have an editable created date field on the user edit form, to be able to change the join date of your users, you can use the following code
this is to be dropped into your custom site module (if you dont have one, you need to create it, see drupal docs on creating modules)
/**
* Implementation of hook_user().
*/
//* function sitemodule_user
function sitemodule_user($op, &$edit, &$account, $category = NULL) {
switch ( $op ) {
case 'form' :
if ($category != 'account' || !user_access('administer users')) break ;
$form = array() ;
$form['sitemodule'] = array(
'#type' => 'fieldset' ,
'#title' => t('Sitemodule user settings') ,
'#description' => t('Custom user settings.') ,
'#tree' => TRUE ,
'#collapsible' => TRUE ,
'#collapsed' => FALSE
) ;
$created = getdate($account->created);
$form['sitemodule']['_created'] = array(
'#type' => 'value' ,
'#value' => $account->created
) ;
$form['sitemodule']['created'] = array(
'#type' => 'date' ,
'#title' => t('User joined date') ,
'#description' => t('Set the user created date.') ,
'#default_value' => array('year' => $created['year'], 'month' => $created['mon'], 'day' => $created['mday']) ,
) ;
return $form ;
case 'validate' :
if ($category != 'account' || !user_access('administer users')) break ;
$value = $edit['sitemodule']['created'];
$value_ts = gmmktime(0, 0, 0, $value['month'], $value['day'], $value['year']) + 43200;
if ($value_ts > time() + 43200) form_set_error('sitemodule', t('Date must be in the past.')) ;
break ;
case 'update' :
if ($category != 'account' || !user_access('administer users')) break ;
$value = $edit['sitemodule']['created'];
$edit['sitemodule']['created'] = NULL;
if ($value == $account->sitemodule['created']) break ;
$value_ts = gmmktime(0, 0, 0, $value['month'], $value['day'], $value['year']) + 43200;
db_query("UPDATE {users} SET created = %d WHERE uid = %d", $value_ts, $account->uid);
break ;
}
} // function sitemodule_user */
if youre wondering about the gmmktime + 43200 hack, its because i had no idea how drupal manages the timezone on the created users or which functions.. fast hack, please drop a line if you know otherwise
$category != 'account' i think makes sure this is node/%/edit, or should i use arg() better?
i dont need 'insert' handling because i only change the edit 'form', and not the 'register'/admin create one
p.s. im not sure what to set the status of this request to.. or if this is the proper place to contribute this
thanks
Comments
Comment #1
gábor hojtsyIts not really the good way to post such suggestions. RTBC issues linger in the queue waiting to be committed, and this is not something to commit. The best way to keep it linger forever could be to set it to active, but thats not really true. If you set it to fixed (although conceptually correct) it will be set to closed after two weeks, at which point its not listed in issue queues anymore. However, it will appear in search results. Maybe its still the best way to set to fixed.
Anyway, I suggest you use the forums to post such suggestions.
Comment #3
jeremymears commentedWould this code work with D7? Really need it for users I'm migrating