form_state['values'] generating error undefined index: values I am having a simple form like this. I want to read the ID value in the middle of the form. When I try to get it using $fromvalues = $form_state['values']['id']; it gives the following error:


  Undefined Index: values in templates_form()


function templates_form_add($form, &amp;$form_state, $templates = NULL) {
  $templates = entity_get_controller('templates')-&gt;create();     
  return templates_form($form, $form_state, $templates); 
 }

 function templates_form($form, &amp;$form_state, $templates) {
   $form = array();

   $form['id'] = array(
     '#title' =&gt; t('ID'),
     '#type' =&gt; 'textfield',
     '#default_value' =&gt; isset($templates-&gt;id) ? $templates-&gt;id : '',
     '#description' =&gt; t('Unique Id'),
     '#required' =&gt; TRUE,
     '#maxlength' =&gt; 255,
     '#disabled'=&gt; empty($ntemplates-&gt;id) ? FALSE : TRUE,
   );

   $fromvalues= $form_state['values'];

   $form['city'] = array(
     '#title' =&gt; t('city'),
     '#type' =&gt; 'select',
     '#options' =&gt; $cities,
     '#default_value' =&gt; isset($templates-&gt;city) ? $templates-&gt;city: '',
     '#required' =&gt; TRUE,
     '#maxlength' =&gt; 255,
     '#disabled'=&gt; empty($templates-&gt;id) ? FALSE : TRUE,

   ),
The error indicates precisely what is going on: during the initial call of templates_form() the $form_state['values'] does not yet exist. This will exist in a future ajax call (if you do ajax) and in validate and submit functions. You better check if it exists first with isset or empty.