I want to get more info from mij users when they register.
With the standard profile.module i have the following options:

* single-line textfield
* multi-line textfield
* checkbox
* list selection
* freeform list
* URL
* date

But i want radio buttons to select 1 option from multiple options.
This can be done with list selection, but i prefer radio buttons.

can some one help me with this?

Comments

Renze’s picture

Any one?

MattKelly’s picture

I'd really like to know this too. Would this require editing the core?

senpai’s picture

I'm looking for this option as well, because I need to add a keyboard-navigation-friendly set of radio buttons to the profile for Gender. Hmm, this looks like it's gonna take a fair bit of work!
--
Joel Farris
"...and that's the way it oughtta be!"

****
Joel "Senpai" Farris | certified to rock score

rungss’s picture

Has anyone solved this??

I too need to add a profile field using a radio button..

Has anyone worked out the best way to achieve this??

dwees’s picture

You shouldn't need to alter the core module, since you should be able to use hook_form_alter to assist you. All you would have to do is create a minimal module (you might only need hook_info and hook_form_alter) to handle the alteration of the form.

Now if you want additional fields in the profile, that should also be possible, but you may have to update the database yourself (and add a field to the profile table) and write some slightly more complicated code.

I'm in the middle of using hook_form_alter myself, and what I found very useful was something called the 'scratch' module which prints out all of the information about a current form on the bottom of the page which is great for development.

Do some searching around this site about the things I've mentioned, this is an excellent small module to get you started.

Dave

syngi’s picture

You don't happen to have a link to that module? I can't find it.

kevin francis’s picture

Here's a simple solution to the problem by the way:

$form['More About Me']['profile_drinker']['#type'] = 'radios';
$form['More About Me']['profile_drinker']['#options'][0] = 'Not specified';

The reason for the second line is that in a drop down you have a -- option, but that doesn't look nice in a set of checkboxes. More About Me was the form tab in question for me, and profile_drinker the field. Use with hook_form_alter.

syngi’s picture

Please note that you'll have to create the profile field first and make it a 'list selection'.
And I believe you can also set the field required, this will remove the first 'empty' options from the list.

Using the hook_form_alter didn't work for me. I tried 'profile_form_alter', but it only gets triggered on user/1/edit and not on any category page (e.g. user/1/edit/category+name). The alternative I found out to work too is to modify the function profile_form_profile in 'modules/profile/profile.module'.
By putting
$fields['Category name']['field_name']['#type'] = 'radios';
at the bottom of the function, just before returning the $fields you can come to the same result.
(The category name and field name are the ones you specified when creating the field.)

I was a bit worried that a required field which was left empty would pass the validation because of the form modification, but it works great!

syngi’s picture

I was using the hook in my template.php file, which actually should not work at all. The hook can only be used in a module. So just using the function in 'modules/profile/profile.module' did the trick. Of course the best way to do this is to write a separate module.

nobarte’s picture

Please note that you'll have to create the profile field first and make it a 'list selection'...

Write in your separate module and you will get radio button:

<?php
function yourmodulename_form_alter($form_id, &$form) {
  if ($form_id == 'user_register') {
    $fields['Category name']['field_name']['#type'] = 'radios'; 
    return $form;
  }
}
?>
rusdvl’s picture

What are you actually suppose to do here? I created a module, which just contained MODULE_NAME.module and the function that you posted. But it does not apply the changes... it does if I do it directly on the profile_form_profile function, but I dont wanna do it in core as I will have to remember to change it every time theres an update.

Can someone post some instructions on how to implement this in a custom module?

Cheers

nobarte’s picture

It works for me in a custom module (Drupal 5) which contained the following function:

function customModuleName_form_alter($form_id, &$form) {
  // print $form_id; // you can get form_id for any form.
  // User register form:
  if ($form_id == 'user_register')
  { 
    $form['Your Profile Category Name']['profile_yourProfileFieldName']['#type'] = 'radios';
    return $form;
  }
}