I have overriden user-register.tpl.php and in it I would like to render same checkbox twice (so that I can submit if either of them have been checked and they are the same I just need to display them twice).


<div class='field1'>
   print render($form['field_add_option']);
<div class='field2'>
   print render($form['field_add_option']);

But this gives same field with same id with same name which is to be expected. Is there a way to change name and id of field before rendering?

I have tried to change the name like (before the second one)
$form['field_add_option']['und']['#name'] = 'test1';

But the label for and name of checkbox are still the same.


The select element don't have #name atribute (Form API Reference). You can implement the hook_form_alter() in a custom module.

  * Implements hook_form_alter().
function YOUR_MODULE_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'YOUR_FORM_ID') {
    //here you can make the copy
    $form['field_add_option_copy'] = $form['field_add_option'];

You can read this: Creating modules - a tutorial: Drupal 7.x

| improve this answer | |
  • 1
    @MePo a pleasure help you, good luck in your projects ;-) – Adrian Cid Almaguer Jan 19 '16 at 12:04
  • @MePo : About Just one more question": are you aware that changing the original question after it was answered is not compliant to the rules of this site? You should really post that as a new question ... – Pierre.Vriens Jun 2 '16 at 19:18
  • @Pierre.Vriens You are right, sorry. Deleted the comment – MePo Jun 3 '16 at 5:32
  • @MePo ok, and why not create a new question for it? – Pierre.Vriens Jun 3 '16 at 5:35
  • @Pierre.Vriens Its because at the end i figured it out. And forgot that i posted here as comment, again my bad will pay more attention to that. But thank you for noticing this – MePo Jun 3 '16 at 5:42

You need to use hook_form_alter to add your additional fields to the user register form so it's a proper field. Or alternatively add the field to the user object within /admin/config/people/accounts/fields and tick the box to tell it to appear on the registration form.

| improve this answer | |
  • But i was wondering how could one "clone" a field but thanks for the explanation – MePo Jan 19 '16 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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