Need block context in hook_form_alter I'm trying to get my module to work: it replicates an exposed filter of a view into a block to display on other pages. Altering the form generally works, but it unfortunately works globally, ie. my changes are also applied to the original filter form on the views page.  That's because I use a simple checking of $delta which does not give me a context - sort of module signature that embedded the form.

I tried both hook_form_alter and hook_form_FORMID_alter - the variables passed to those functions don't seem to carry that info though.

Is there a way to get this kind of context?
If you are displaying this block on only certain pages, looking at $_GET['q'] or arg(#) will tell you that path or one of its arguments, so maybe you can switch on that?  eg, path/to/my/page is in $_GET['q'] and arg(2)=='my'.  Note that paths to nodes are system paths, not aliases, so the path might be just node/# but you can do a drupal_get_path_alias() to find it if need be.  If you are displaying the block only on certain node types, you can grab $node=menu_get_object() and then switch on $node-&gt;type as an example as well.  In fact, if you do it that way, $node-&gt;path should already point to the aliased path, and it's already cached for your performance pleasure :)  

Oh, and failing all the above, you could do all of this in a custom module block, too, eg, in there do something like:

$block['subject']='// subject goes here';
// do the hook form alter
$content=views_embed_view( // the view in question );
$block['content']=$content;

return $block;


All of the php above presumes D6, minor changes apply to D7, but since it is being called in the block itself, the form alter should only change the view there (unless it is also being displayed elsewhere on the same page)