2
function test_data_import_form($form, &$form_state) {
    $form = array();

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

    $form['import_data'] = array(
        '#type' => 'file',
        '#title' => t('Upload data file'),
        '#size' => 22,
        '#required' => TRUE,
    );

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

    return $form;
}

Please see my form code above. I am trying to import a file through this form, but the file I am trying to import is not recognized as it is throwing "Required field error". Please help me with this.

1

I tried #file_managed instead of the file, and then I am able to upload the files into the application. But, this option stores the file in managed_file table in the database with a temporary storage. The file details are not visible in the dsm() (devel module).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.