1 form_example_tutorial.inc form_example_tutorial_10_validate($form, &$form_state)

Validate handler for form_example_tutorial_10().


modules/examples/form_example/form_example_tutorial.inc, line 731
This is the Form API Tutorial, originally from the Backdrop handbook.


function form_example_tutorial_10_validate($form, &$form_state) {
  $file = file_save_upload('file', array(
    // Validates file is really an image.
    'file_validate_is_image' => array(),
    // Validate extensions.
    'file_validate_extensions' => array('png gif jpg jpeg'),
  // If the file passed validation:
  if ($file) {
    // Move the file into the backdrop 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 to the site's file folder."));
  else {
    form_set_error('file', t('No file was uploaded.'));