[development] Creating multiple login blocks with, different validation rules.

nan wich nan_wich at bellsouth.net
Fri May 14 01:59:09 UTC 2010


IIRC, he said he was using MultiBlock, which might change the form_id; it definitely changes the module name and delta for the block. I'm guessing the first problem is using MultiBlock for the user_login_block, as the user module is not multiblock enabled. 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.
 
Nancy E. Wichmann, PMP
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.



________________________________

From: Earnie Boyd 

Anth wrote:
> Hi Earnie,
> 
> Thanks for the answer and that's one of the things to do, but my problem
> at the moment with that path is that in hook_form_alter there doesn't
> seem to be anything that I can use to identify which block it is. Am I
> missing something obvious?
> 

The third argument of hook_form_alter is the $form_id and for user_login_block that would be user_login_block.  Both $form and $form_state are a pass-by-ref variable so any changes you do happen to the form and/or form_state before they get rendered.

> If there is nothing in the $form then what I think I actually want to do
> is use some code to generate the form and as I have access to the $form
> array to put in my own validation rule or hidden $form element or
> whatever to distinguish between the different blocks.

You can add your own validation and submit handlers for the form using hook_form_alter as well.  You just need to make sure that your hook_form_alter function uses a pass by ref for the $form parameter and add your validation or submit handlers as appropriate.

> So I'm trying to
> generate the user_login_block myself so I can alter the $form array but
> can't get it to work. In my block code if I call
> drupal_get_form('user_login_block') for the block content everything is
> fine but I can't alter the form object. So I'm trying to do the same
> steps as drupal_get_form, i.e. the code below and the user login block
> displays but there is a bunch of stuff missing from it so it doesn't
> actually submit.
> 
> Am I making this harder than I need to for what I'm trying to achieve?
> 

If you're doing the same code as drupal_get_form then you are most likely doing the wrong thing and making it harder than it needs to be. Be sure to look for the examples at api.drupal.org.

-- Earnie
-- http://progw.com
-- http://www.for-my-kids.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20100513/ebd87c52/attachment.html 


More information about the development mailing list