<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial, helvetica, sans-serif;font-size:12pt"><DIV></DIV>
<DIV>Great, Anthony. I suggest that you write up a little snippet&nbsp;page for the Handbooks so it can be found with a search.</DIV>
<DIV>&nbsp;</DIV>
<DIV>BTW, remember the array_unshift technique, because you will need it again, especially if you do any node_form alters. I worked that same one out some time ago and am amazed at how many times I have to get my&nbsp;submit handlers to fire first. I just had to do it again a couple of days ago on the comment_form. So documenting this in the handbooks&nbsp;could save people a lot of time in the future.<BR>&nbsp;</DIV>
<P><FONT face="bookman old style, new york, times, serif" color=#ff007f size=4><EM><STRONG>Nancy E. Wichmann, PMP</STRONG></EM></FONT></P>
<P><FONT face="arial, helvetica, sans-serif">Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.</FONT></P>
<DIV><BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: arial, helvetica, sans-serif"><BR>
<DIV style="FONT-SIZE: 10pt; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face=Tahoma size=2>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Anth &lt;malkouna@yahoo.com.au&gt;<BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> development@drupal.org<BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Fri, May 14, 2010 2:02:50 AM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: [development] Creating multiple login blocks with, different validation rules.<BR></FONT><BR>Hi,<BR><BR>Thanks for the tips everyone. Worked it out, will describe what I ended up doing in case it's useful to anyone.<BR><BR>Nancy and Earnie, I was using MultiBlock and the core of the problem for me was that they *don't* change the $form_id so there is nothing to differentiate them. Alex, yep, I'd started to look at hook_forms so your tip was a good kick in the right direction. Lee, by the time I got your email I'd worked it out :)<BR><BR>So as an example, I had to throw away MultiBlock and generate the blocks on my own but it was pretty easy to do. My
 application is a timesheet application and there is a role called 'candidate' that needed a separate login. The only real problems I had after getting the hang of all that is for some reason I had to shift my validation function into the first slot (see comments in hook_form_alter) to get it to fire, and if I do a form_set_error(), because the elements are the same name the red error border appears on both, but hey I can live with that.<BR><BR>in my hook_block:<BR><BR>case 'view':<BR>$block['subject'] = 'Candidate Login';<BR>$block['content'] = drupal_get_form('candidate_login_block');<BR>return $block;<BR><BR>Now because 'candidate_login_block' doesn't exist as a function that can be called by drupal_get_form I want drupal_get_form to be called as drupal_get_form('user_login_block') and to make this happen I set up a hook_forms (note, not hook_form) as below:<BR><BR>function timesheet_forms($form_id, $args)
 {<BR>$forms['candidate_login_block']['callback'] = 'user_login_block';<BR>return $forms;<BR>}<BR><BR>This all means that in my hook_form_alter I can do:<BR><BR>switch($form_id) {<BR>case 'candidate_login_block':<BR>// $form['#validate'][] = '_timesheet_candidate_login_validate';<BR>// The line above doesn't seem to result in my validation function getting called so had to use the form below.<BR>array_unshift($form['#validate'], '_timesheet_candidate_login_validate');<BR>break;<BR><BR>In my function _timesheet_candidate_login_validate I can do whatever I want to invalidate the form (I called user_load with the entered field and checked its roles). Done.<BR><BR>Thanks,<BR>Anthony.<BR><BR>On 14/05/2010 3:37 PM, Lee Rowlands wrote:<BR>&gt; <BR>&gt; For a decent Hook_forms example look to ubercart’s uc_product, it uses hook_forms to register the ‘add to cart’ forms : http://api.lullabot.com/uc_product_forms<BR>&gt; <BR>&gt; *&gt;* I think the answer
 about using hook_forms is the way to go, but last I looked the API docs were really bad on that hook.<BR>&gt; <BR></DIV></DIV></div></body></html>