By medc77 on
I am using the Profile2 module.
I would like to alter one of the Profile2 forms, however these forms are apparently built dynamically, therefore I don't think i can use hook_form_alter() or drupal_get_form(). Is this correct?
How can I alter and then display a Profile2 form? anyone knows?
Comments
Hi, You can do it using
Hi,
You can do it using form_alter function from your template.php or using your custom module.
Configure the $form array as you wish!!
Try it.
Thanks,
Niyas
profile2.api.php
Have you worked it out yet? Check out profile2.api.php at the very bottom:
* Modules may alter the profile2 entity form regardless to which form it is
* attached by making use of this hook or the profile type specifiy
* hook_form_profile2_edit_PROFILE_TYPE_form_alter().
The other Andrew Morton
This does not help
I am trying to make a profile2 field required for some users. I have created a profile2 profile with the machine name of more_info. Initially I added two fields firstname and lastname and made the firstname field required.
I initially tried to make this alteration with hook_form_alter. I saw a reference to problems when profile2 loads after my module but altering the name of my module did not change this behavior.
I then saw a reference to hook_form_profile2_edit_PROFILE_TYPE_form_alter at https://drupal.org/node/1198522 and later at: http://drupalcontrib.org/api/drupal/contributions!profile2!profile2.api....
I created a simple module and included this function:
The code successfully dumps the form so it is getting evoked, but unfortunately, when the form loads the lastname field remains optional. This is the same as when I tried with hook_form_alter.
You should be able to make a
You should be able to make a field required through the interface when you added it. Just go back to "manage fields" for your profile and edit the ones you want and click the required checkbox.
The other Andrew Morton
That actually should work.
That actually should work. You might want to dump your form after you altered it. And double check the validity of your changes.
What I have done with implementing that profile2 hook was setting a field to be hidden, because it's set automatically. For some reasons I did not want to set this using the field settings.
And BTW instead of using
['und']you probably should use[LANGUAGE_NONE].I got this to work, in my
I got this to work, in my case we have a profile type called "parent" which contains (among other things) a "last name" field. We wanted the last name to be optional for most users but required for users with the "parent" profile type applied to their account. This is what worked for us:
How come I didn't see
How come I didn't see ".....[LANGUAGE_NONE][0]['value']....." in the devel? e.g:
The most I can see is "....['und'][0].....", e.g:
$form['profile_main']['field_profile_last_name']['und'][0]['#required'] = true;What's the different between them actually?
LANGUAGE_NONE is a php
LANGUAGE_NONE is a php constant that represents no language defined ('und'). Notice how it is all caps and has no quotes. Using 'und' will also work, but LANGUAGE_NONE is more correct.
The other Andrew Morton
Thanks, worked for me tooo. ;)
Thanks, worked for me tooo. ;)
Thanks! This worked like a
Thanks! This worked like a charm!
I wonder how to write if I
A) I wonder how to write if I want to target the user that has no role assigned, plainly the registered user alone.
if (in_array('care provider', array_values($user->roles))){ ..}B) What if I want check more than 1 role assigned. E.g If user role is "Administrator" OR "Webmaster" than do something ......
Try:<?phpif (in_array('care
Try:
The other Andrew Morton