1 form_example_tutorial.inc form_example_tutorial_10($form_state)

This is Example 10: a form with a file upload field.

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

See also



Related topics


modules/examples/form_example/form_example_tutorial.inc, line 689
This is the form API tutorial.


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. backdrop 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;