Hi all, I'm new with Drupal development, and so far amazed with how easy is to hook up into Drupal's framework to build modules.

I'm trying to write a module to import a list of users to drupal (a CSV or XML file with some custom fields that will be mapped to custom profile fields), and trying to use this project to learn how to build modules.

I already built the skeleton of my module, made the form and added an input 'file' into the settings form. What I would like to do now is to save this file into the server, so then I can process it to create all the users. I cannot get where is there I can access the file data to save it.

This is the form I'm creating

function spp_userimport_admin_settings() 
{
	
	$form['spp_userimport_inputformat'] = array(
		'#type' => 'radios',
		'#title' => t('The file you\'re importing is in this format'),
		'#options' => array(
			t('CSV (Comma Separated Values)'),
			t('XML (See schema)')
		),
		'#description' => t('Input format for the file to import.'),
		);
		
		$form['spp_userimport_file'] = array(
			'#type' => 'file',
			'#title' => t('The file to upload and import'),
			'#description' => t('Select the file with the users to import'),
			'#size' => 40,
		);
		
		$form['#attributes'] = array('enctype' => "multipart/form-data");
		
		return system_settings_form($form);
		
}

and this is the way I'm trying to access the file uploaded



function spp_userimport_admin_settings_submit($form_id, $form_values) 
{
	drupal_set_message($form_values['spp_userimport_inputformat']);
	drupal_set_message($form_values['files[\'spp_userimport_file\']']);

}

I've even tried to access it using the file_check_upload function, but with no success yet. Also, I've noticed that when the radio is selected with the first option (ie, the value is 0) I get nothing in $form_values['spp_userimport_inputformat'], but when the second option is selected, I get the correct value '1'.

Do you know what is that I'm doing wrong? Is there something I'm not getting about this thing?

Comments

naurisr’s picture

Add

  $form['#attributes'] = array('enctype' => "multipart/form-data");

in spp_userimport_admin_settings