We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Elements rendered by Form builder

...have "id" parameter same as a "name" but I not set it! And if I'll have more than one similar form on page it will .... bad. Thats how I add elements to Form class:

$message = new TextArea('message', array(
    'class' => 'textarea-field',
    'placeholder' => $t->form->post->message->placeholder
));
$message->addValidator(
    new PresenceOf(array(
        'message' => $t->form->post->message->required
    ))
);
$this->add($message);

That's how I render it:

{{ form.render('message') }}

That's what I get:

<textarea class="textarea-field" placeholder="Express your thoughts here" name="message" id="message"></textarea>

How to trick?



98.9k

Phalcon\Tag automatically sets the "id" with the same name as the element's name. You can change the id or set an empty string:

$message = new TextArea('message', array(
  'class' => 'textarea-field',
  'placeholder' => $t->form->post->message->placeholder,
  'id' => 'other-id'
));

Or set the id to empty string

$message = new TextArea('message', array(
  'class' => 'textarea-field',
  'placeholder' => $t->form->post->message->placeholder,
  'id' => ''
));

Thanks! It helps!

There are no way to not render id at all, coz output is: <textarea class="textarea-field" placeholder="Express your thoughts here" name="message" id=""></textarea>

Where's the problem? id="" equals no id at all.



72

It's useless trailing code. I also never use ID on form elements and would appreciate a 'id' => null option or a global disable.