Multiple forms and required fields affecting hook_form_FORM_ID_alter() When creating a new content type, the $form_id is correctly picked up in my module.  Let's say in my example, my form is called the 'foo_form'.  The below hook_form_FORM_ID_alter function works fine when I go to add/content/foo-form

function MyModule_form_foo_form_alter(&amp;$form,&amp;$form_state,$form_id) {
  echo 'It works!';
}


The problem is that my content type has some required fields.  If the user does not fill them in all out and submits, then the submission fails as expected.  

The problem is that now on the error page telling the user that he or she needs to fill out the required fields, the $form_id is no longer 'foo_form', but instead named 'search_block_form' because on all my pages I have a search block on the left side bar.  Now my hook_form_FORM_ID_alter() does not get invoked because my module is getting 'search_block_form' as its $form_id instead of 'foo_form'.

I tried using hook_form_alter(), which works globally, but because there are 2 $form_id's on this required fields error message page, my MyModule_form_foo_form_alter() gets called twice (once for 'search_block_form' and 'foo_form')!  

How do I resolve this issue, other than exclude displaying the search form block when adding new content?  How do I make 'foo_form' the primary $form_id???? I find this odd since if I go to add a new content, Drupal is "smart" enough to ignore the 'search_block_form' $form_id.

EDIT: My code to test visibility about what $form_id's are present before submitting and after submitted without filling in all the required fields.

function MyModule_form_alter(&amp;$form,&amp;$form_state,$form_id) {
  case 'search_block_form':
    //this one always shows up
    echo $form_id . "&lt;br&gt;";
  break;
  case 'foo_form':
    //does *not* show up when submitting form 
    //with missing required field values
    echo $form_id . "&lt;br&gt;";
  break;
}
To do form validation use the form API validation capabilities:

http://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7#validation

http://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7#validate