0

I am building a custom module where the user needs to upload an image. Here is the code for my form:

function floor_map_form($form, &$form_state) {
        $form['file'] = array(
            '#type '        => 'file',
            '#title'        => t('Choose a file'),
        );
        $form['center'] = array(
            '#type'     => 'textfield',
            '#title'        => t('Center'),
            );
        $form['country'] = array(
            '#type'     => 'textfield',
            '#title'        => t('Country'),
            );
        $form['region'] = array(
            '#type'     => 'textfield',
            '#title'        => t('Region'),
            );
        $form['submit'] = array(
            '#type'     => 'submit',
            '#value'    => t('Submit'),
            );

        return $form;
    }

The only thing that shows in the browser are the text fields and submit button, the file upload field is nowhere in the page or html for the page.

1 Answer 1

1

Does this look wrong to you:

'#type ' => 'file',

it's not '#type'

3
  • This is what the Form API uses. api.drupal.org/api/drupal/… Also every other example I can find: drupal.org/node/220944 , drupal.org/node/85922 Also, if you know it is incorrect, why not show the correct way? It's a question and answer service, I'm not here for me to say something's not working and for someone to say "You did it wrong". We are here to help each other.
    – slpcc63
    Feb 26, 2014 at 21:11
  • No, sigh ........ you have an extra space in "#type ". You don't have the array key "#type". Scrutinize your code better.
    – tenken
    Feb 26, 2014 at 21:16
  • I said "does this look wrong to you" and quoted 1 line from your code, and it said it's not this exact string: "#type". If you don't read your code letter-for-letter these types of errors will always get you. I don't want to tell you literally "you have an extra space" because you don't learn how to read your code better -- you learn to ask others how debug your code for you. You may not approve of my methods but I am trying to help you; while not spelling out the answer for as the error not an API question, its a syntax issue. Thanks for your time.
    – tenken
    Feb 26, 2014 at 21:27

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