I'm trying to develop a module, and I can't seem to find the file that's uploaded from a form api containing a file input. Here's my code...

function form($form_values = NULL) {
  // Using multistep... code excluded
  
  //  Step 1
  if($step == 1) {
    $form['file'] = array(
      '#type' => 'file',
      '#description' => 'Use an archived file, such as a zip file, or a tar.gz file.');
    $form['upload'] = array('#type' => 'submit', '#value' => t('Upload'));
  } else {
    //haven't gotten this far yet
  }
  return $form;
}

function form_validate($form_id, $form_values) {
  if(!file_check_upload('file')) { //this always returns false, I've tried a lot of diff. values
    form_set_error('', 'A valid file must be uploaded'); 
  }
}

function form_submit($form_id, $form_values) {
  //Never gets to here, due to form_validate
}

I've tried uploading different files, with different extensions, and I've tried it both on my local linux box, and a server, so I think it's a code problem, I just don't know what.

Comments

AndyColson’s picture

I had to add this:

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

do you have that some place?

-Andy

bradlis7’s picture

That was the problem! They should include that in the documentation somewhere.

--
Bradlis7.com | Churchofchristnet

sepeck’s picture

Welcome to the team. Please write a handbook page. Take your best guess were it should go and if it doesn't work there, we'll move it for you. It's much easier to move something that is written then move something that isn't.

As a bonus you will get your name listed here as a contributor.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

bradlis7’s picture

Heh, thanks. I was thinking it could be put in an existing page, but I'll add a new page.

--
Bradlis7.com | Churchofchristnet