limit amount of upload images (through imagefield module) to only 1 by code/programmatically I use image field with possibility to upload unlimited images. BUT under the user registration, I want to limit the possibility to just one image. So that the anonymous user, who wants to become a registered user, can only upload one image. After they become users, then they can upload as many images as they wish.

Does anybody know how to do that?
You want to use a hook_form_alter to process this for just that form, ex.

function mymodule_form_alter(&amp;$form, $form_state, $form_id) { 

    if ($form_id == 'user_register') {
        // do stuff here
    }

}


The 'stuff' is the real challenge, especially since you are allowing for unlimited uploads. There is a previous post on this with a solution for a limited set (&lt;10):

https://stackoverflow.com/questions/5701488/change-fields-number-of-values-per-role

My suggestion for resolving this (though not ideal) would be to add a custom handler as part of your logic that would check to see if one already exists and gently prod them not to add more than one. 

if ($form_id == 'user_register') {

    $form['&lt;image field name&gt;']['#element_validate'] =&gt; array('_mymodule_only_one_image'),

}


and then for your validation function, you could simply test whether a 2nd image exists and prod the user to only submit one. Rough psuedo-code example here, haven't tied this to an actual form.

function _mymodule_only_one_image($element, &amp;$form_state) {

    if (!empty($element['&lt;image_field_name&gt;'][1])) {
        form_error($element, t('Please only upload one image');
    }

}


Another option would be to try and disable the ajax handler that initiates the 2nd upload through your own custom jquery override, which you could also add in to this custom form through the above form_alter.