2

I want to modify my register page and add some fields from 'profile' content, for example: gender.

So Ive got:

function mysite_preprocess_user_register(&$variables) { unset ($variables['form']['Personal Information']['profile_gender']['#description'] ); .... }

In this point when i print_r profile_gender Ive got:

Array ( [#type] => select [#title] => Gender [#default_value] => [#options] => Array ( [0] => -- [Select] => Select [Male] => Male [Female] => Female ) [#required] => 0 [#post] => Array ( ) [#programmed] => [#tree] => [#parents] => Array ( [0] => profile_gender ) [#array_parents] => Array ( [0] => Personal Information [1] => profile_gender ) [#weight] => 0.003 [#processed] => 1 [#attributes] => Array ( ) [#input] => 1 [#size] => 0 [#multiple] => [#process] => Array ( [0] => form_expand_ahah ) [#name] => profile_gender [#id] => edit-profile-gender [#value] => [#defaults_loaded] => 1 [#sorted] => 1 )

And when I want to change #type to 'radios' displays me nothing..

Like:

  $variables['form']['Personal Information']['profile_gender']['#type'] = 'radios';
  $variables['form']['Personal Information']['profile_gender']['#options'] = array('0'=>t('Male'),'1'=>t('Female'));
  $variables['form']['Personal Information']['profile_gender']['#default_value'] = 'Male';

    $variables['gender'] = drupal_render($variables['form']['Personal Information']['profile_gender']); 

Any ideas how to change that from select list to radios(male/female)?

1
  • Profile lets you display its fields on the register page. Why not using this ?
    – Countzero
    Commented Mar 28, 2012 at 7:04

1 Answer 1

2

The preprocess functions are about rendering the output. Removing and adding form element with FAPI must be done earlier.

You have to do this with hook_form_alter. It's also very likely that you have to add a custom submission handler to process and save the user input. You can hook in your handler in hook_form_alter as well.

2
  • and how can I use it for edit this field? Any example?
    – mihaueq
    Commented Mar 28, 2012 at 10:51
  • If anyone is intrested (I cant reply my own post): function my_site_form_alter(&$form, $form_state, $form_id) { // add radios if ($form_id == 'user_register') { $form['Personal Information']['profile_gender']['#type'] = 'radios'; $form['Personal Information']['profile_gender']['#options'] = array('0'=>t('Male'),'1'=>t('Female')); $form['Personal Information']['profile_gender']['#default_value'] = 'Male'; } }
    – mihaueq
    Commented Mar 28, 2012 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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