form_example_tutorial_10

6 form_example_tutorial.inc form_example_tutorial_10($form_state)
7 form_example_tutorial.inc form_example_tutorial_10($form_state)
8 form_example_tutorial.inc form_example_tutorial_10($form_state)

Example 10: A form with a file upload field.

This example allows the user to upload a file to Drupal which is stored physically and with a reference in the database.

See also

form_example_tutorial_10_submit()

form_example_tutorial_10_validate()

Related topics

1 string reference to 'form_example_tutorial_10'

File

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

Code

function form_example_tutorial_10($form_state) {
  // If you are familiar with how browsers handle files, you know that
  // enctype="multipart/form-data" is required. Drupal takes care of that, so
  // you don't need to include it yourself.

  $form['file'] = array(
    '#type' => 'file', 
    '#title' => t('Image'), 
    '#description' => t('Upload a file, allowed extensions: jpg, jpeg, png, gif'),
  );

  $form['submit'] = array(
    '#type' => 'submit', 
    '#value' => t('Submit'),
  );

  return $form;
}
Login or register to post comments