User login

Allow people to upload user pictures during registration

Well that's annoying.

Spend a good chunk of time creating a module to address a need, return to the thread that's been discussing it since 2006 June to post your efforts and discover it's just been updated to report that the module has been around since 2007 November.

[Download Agaric's user_reg_picture module anyway.]

So if you need to to enable the upload of user pictures during registration, this is the user picture on registration module that makes Drupal core work as it should. If you are using bio or nodeprofile you do not need this.

Register with Picture
http://drupal.org/project/reg_with_pic

And you will have found this page because we at Agaric put in every keyword imaginable in writing about this. Yes we sometimes wish others were more like us. It would have saved a lot of work below! If you wish more people were like us to hire us so we'll have more money to invest in our brain wave transformation device.

So, for the record, below is my development process to developing my version (attached) of the module linked to above.

Thanks in part to the archaic user module, a 2 hour estimate to add user picture upload to the client's custom registration form has become a journey through hell because Drupal core doesn't even let you upload a user picture when uploading. and all the functions are insanely large and have hard-coded special cases in them and the hooks aren't comprehensive enough

Asks, no answer:
user registration - avatar select or upload image?
http://drupal.org/node/279802

How do I get a registration form that has all options in it?
http://drupal.org/node/130612

  • The site they were looking at actually had a standard user registration form as the first page and then redirected to a profile content type with everything else.

Clue!

<?php
function user_edit_validate($form_id, $form_values) {
  user_module_invoke('validate', $form_values, $form_values['_account'], $form_values['_category']);
// ...
}
?>

<?php
/**
 * Invokes hook_user() in every module.
 *
 * We cannot use module_invoke() for this, because the arguments need to
 * be passed by reference.
 */
function user_module_invoke($type, &$array, &$user, $category = NULL) {
  foreach (module_list() as $module) {
    $function = $module .'_user';
    if (function_exists($function)) {
      $function($type, $array, $user, $category);
    }
  }
}
?>

Answer in comments?

http://drupal.org/node/69814

jezz, u have hack a little in user.module
reset.to - November 21, 2007 - 08:15

write your own form_alter function as mentioned above. than add your validate function.

<?php
function mymodule_user_register_validate($form_id, $form_values, &$form){

    // If required, validate the uploaded picture.
    if ($file = file_check_upload('picture_upload')) {
        // getting next id - you cannot use db_next_id!!
        $res = db_query('SELECT MAX(uid) uid FROM {users}');
        $user = db_fetch_object($res);
        // this is now our future user
        $user->uid++;
        user_validate_picture($file, $edit, $user);
    }
}
?>

now the $edit["picture"] will be filled by the call of user_validate_picture. Thus you have to prevent an error when the user.module call it's own hook_user. So simply add this line:

<?php
function user_validate_picture($file, &$edit, $user) {
  global $form_values;
  if($user->uid == 0 ) return;

  // function continues here ...
}
?>

<?php
function join_form_submit( $form_id, $form_values ) {
// ...
// ben-agaric added...  iknow it's the validation function but mostly it's for
    $edit = $form_values;
    // If required, validate the uploaded picture.
drupal_set_message('<pre>'. var_export($edit,TRUE) .'</pre>');
    if ($file = file_check_upload('picture_upload')) {
drupal_set_message('<pre>'. var_export($file,TRUE) .'</pre>');
      user_validate_picture($file, $edit, $user);
    }
// ...
}
?>

And the result says picture is NULL.

array (
'step' => 2,
'destination' => 'earthkeepers',
'earthkeeper' => 1,
'reset' => '',
'mail' => 'ben@agaricdesign.com',
'name' => 'best',
'pass' => 'test',
'passc' => 'test',
'picture' => NULL,
'yob' => '1974',
'agree' => '1',
'user_earthkeeper_mailings' => '1',
'captcha_seed' => '17e6cce60155681135f3db554182fd7c',
'captcha_answer' => 'FC4T7',
'op' => 'Join Changents',
'submit' => 'Join Changents',
'form_build_id' => 'eef98cd5a5f50eee041a21581ba696ee',
'form_id' => 'join_form',
'is_earthkeeper' => 'earthkeeper',
)

And the triumphant module which is quite different from these false starts (and uses form_alter and custom validate and submit handlers, whereas Register with Picture uses hook_user) is below.

So to pretend I didn't totally waste my time, my user_reg_picture module may be a better starting place if you need to modify a custom register or join form (which in fact was the case for the client for which this work was done).

Resolution

Searched words: 
Upload user picture during registration add image upload to new user form image picture user picture registration Drupal user picture on registration user picture upload Drupal upload picture registration form register with avatar

Comments

Lifesaver module!

Thanks so much for the module. I downloaded countless others assuming that some MUST include this basic functionality...but no! Sometimes I wonder what the point of Drupal is if I have to spend so long figuring out its internals to get something basic to work.

Great module. Btw, the

Great module. Btw, the Register with Picture module located at Drupal does not work with nodeprofile, while Agaric's does seem to.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.