Is there a difference in Drupal 7 to add a file-upload field on a "normal" form (i.e. a separate page for a modules' configuration) as opposed to the small settings area for a CCK field (the one that appears after clicking on the cog for the field you'd like to modify under the "Manage Display" tab)?
I have a bunch of configuration options for a custom field using hook_field_formatter_settings_form, but am stuck at trying to figure out how to create a file upload field. I'd ideally like to have the user able to browse for an image and upload it without having the page reload. This is all I currently have:
$element['custom_field_name']['image'] = array( '#type' => 'file', '#size' => 48, '#title' => t('Image upload'), '#description' => t("Upload an image."), );
If it is possible to have a file upload field (that uses ajax) in this area, what else must I do?
My file field now looks like this:
$element['custom_field_name']['image'] = array( '#type' => 'managed_file', '#title' => t('Image upload'), '#upload_validators' => array( 'file_validate_extensions' => array(0 => 'png jpg jpeg gif'), 'file_validate_image_resolution' => array('64x64', '10x10') ), '#upload_location' => 'public://default_images/', '#description' => t("Upload an image."), );
This is sort of working: it allows me to upload a file and it goes to
sites/default/files/default_images, but its only temporary. I've been going through the form api reference and it says I need to permanently save it. I am just unsure how where to put this logic. Do I add a
#process key to my file field and call some private function? Or do I create a submit handler? The API reference doesn't go into as much detail as I'd like.