form_example_tutorial_10_validate

6 form_example_tutorial.inc form_example_tutorial_10_validate($form, &$form_state)
7 form_example_tutorial.inc form_example_tutorial_10_validate($form, &$form_state)
8 form_example_tutorial.inc form_example_tutorial_10_validate($form, &$form_state)

Validate handler for form_example_tutorial_10().

File

form_example/form_example_tutorial.inc, line 715
This is the Form API Tutorial from the handbook.

Code

function form_example_tutorial_10_validate($form, &$form_state) {
  $file = file_save_upload('file', array(
    'file_validate_is_image' => array(), // Validates file is really an image. 
    'file_validate_extensions' => array('png gif jpg jpeg'), // Validate extensions.
  ));
  // If the file passed validation:
  if ($file) {
    // Move the file, into the Drupal file system
    if ($file = file_move($file, 'public://')) {
      // Save the file for use in the submit handler.
      $form_state['storage']['file'] = $file;
    }
    else {
      form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
    }
  }
  else {
    form_set_error('file', t('No file was uploaded.'));
  }
}
Login or register to post comments