I am looking for a way to change the default state of o radio button. Do you think this would be possible with Form Defaults?

Comments

metzlerd’s picture

Status: Active » Closed (won't fix)

Changing the default value of a radio is pretty invasive stuff. You also wouldn't really be able to tell whether the default value was a default, or the currently selected value. So in short, I don't think that this can be achieved with form defaults, because the drupal forms api doesn't really distinguish between the current and default values.

roball’s picture

Thanks for clarifying. In particular, I only need to change the radio "Status" on admin/user/user/create to be changed from "Active" to "Blocked". Could you please make any recommendation on how to accomplish this?

metzlerd’s picture

Sure. A custom module that implements hook_form_alter and adjusts the default value. Code would look something like.

function mymodule_form_alter(&$form,$form_state,$formid)
{
  if ($formid == 'user_register) { 
    $form['status']['#default_value'] = 0
  } 
  
}
roball’s picture

Thank you David! I will likely do this in a custom module since I really need this functionality and haven't yet found an existing module that would also be able to do that.

However, then I would need to have yet another module enabled for just this little piece of code...
You wouldn't think of including this feature to your module as an option, would you?

metzlerd’s picture

I'm afraid not (at least at this time) I generally have one custom module on my site that I put all of these kinds of "hacks" in, along with other functions that I might use in PHP theme snippets. I'd advise you to do the same.

If I ever get around to doing a chunk of custom code for the user_register module (there's a separate issue for that) I'll reconsider it. Allowing this functionality for ANY form is just way to dangerous. I've had to draw a similar line around Submit button labels.