Where is the value in a form textfield stored? I have created a simple form that displays a textfield and a submit button. The text field is defined:

$form['upload_file'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('File to read')
  );


When I enter "test" in the textfield and select the submit button, the form moves on to the Validate function which has the following code:

$answer = $form_state['values']['upload_file'];
  if (!$answer) {
    form_set_error('upload_file', "Please enter a file name: ");
  }


And I get the error message indicting that $answer is empty. Do I have the wrong array location for the stored textfield text? Or is there something else I need to do to place the values in the form ito the values array?
The easiest way to debug form related issues I have found is with the devel module

drush dl devel &amp;&amp; drush en devel -y


This module provides a whole host of helpful functions. E.g. in your case you could use this in your validation function:

dsm($form_state['values']);


This would print a lovely formatted array of every value in the form. From there you can drill down to the required value.

I believe you should be checking for:

if (empty(trim($form_state['values']['field_upload_file']))) {
  form_set_error('upload_file', "Please enter a file name: ");
}


Or alternatively, if you are just checking to see if the textfield simply has a value in it, then the better approach would be to use the FAPI and declare:

$form['upload_file'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('File to read'),
  '#required' =&gt; TRUE,
);