0

I am trying to modify a form with a hook_form_FORM_ID_alter within a module though it doesn t seem to have any effect at all when called from within my module.

My code looks like something like this:

function fb_reg_form_user_register_form_alter(&$form, &$form_state, $form_id ){ 
    $form['field_lang_list']['#prefix'] = '<div style="display:none;">';
    $form['field_lang_list']['#suffix'] = '</div>';

   $fbu = fb_facebook_user();
   if ($fbu || is_numeric($fbu)){
   $fb_account = fb_api($fbu);

   krumo($fb_account);
   $form['account']['mail']['#prefix']= '<fb:profile-pic uid="'.$fbu.'" linked="false"></fb:profile-pic>';
    $form['account']['mail']['#default_value'] = $fb_account['email'];
    $form['account']['name']['#default_value'] = $fb_account['name'];
    //$form['account']['name']['#default_value'] = $fb_account['name'];
   }
}

The thing i don't understand is that this works as expected when the hook is called from within the template.php but when in the module it self i can't seem to get it work.

Would anyone have any idea on what s going on?

EDIT: Could this have something to do module weight ?

Many thanks,

4
  • Couple of pointers. Is your module called fb_reg? To hide a field you can change #access to false rather than putting a div around it. Aug 2, 2011 at 14:43
  • Thanks Jeremy, i was aware of this but for some reason witch honselty i don t quite get yet, i can t use the #acccess false otherwise the default value get ignored when submitting the form. Yes my module is called fb_reg
    – silkAdmin
    Aug 2, 2011 at 14:56
  • Does your module name is "feb_reg" ? Are you sure you're altering the correct form (try using hook_form_alter) ? Why don't you use devel with dpm instead of krumo ?
    – tostinni
    Aug 2, 2011 at 14:58
  • yep my module name is fb_reg. I am sure the form is the right name as when i use the same alter function in my template.php it works perfectly
    – silkAdmin
    Aug 2, 2011 at 17:16

2 Answers 2

2

If the part of the form you're altering doesn't exist when you're altering it (if it's put there by some other form-altering module) OR if some other module is altering the form after you and wiping out what you're doing then you can indeed have a module weight problem. The way to find out is to put a dsm() (see devel module) in your code and see what the form looks like before your alter. Or use a debugger of course (recommended!)

1
  • yep seems like it was the problem, thanks a lot for the feedback :)
    – silkAdmin
    Aug 3, 2011 at 12:17
0

If you use form id in function name, you don't need $form_id param.

IMO function name should be

mymodule_form_user_register_alter

3
  • Thanks for your answer, i added that as an attempt to make my form alter function work, but with or without i get the same results :(
    – silkAdmin
    Aug 2, 2011 at 14:57
  • Install Drupal for Firebug and check this form id. Btw did you clear cache?
    – Codium
    Aug 2, 2011 at 15:11
  • Thanks, though i am sure that i got the form name right as when i use the same function in the template.php it work perfectly.
    – silkAdmin
    Aug 2, 2011 at 17:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.