• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Is it safe to keep "name" and "id" the same in every form element?


Well-known member
This could be basic; but I've not found any satisfactory answer so far. So far, I've been keeping the "name" and "id" attributes in any form in my templates the same; without any issues. I'm doing so with an aim to make the styling simpler. I THINK that the "ID" is mainly used for styling the elements, while the 'name' is the attribute required by PHP to do stuff.

Is it safe, or a good practice to keep the name and id attributes the same in every form element?


<input type="text" name="yo" id="yo" .....>


Well-known member
Most of the time, yea though I would suggest adding ctrl_ which requires user input, for example a input with name as "user_id" can have id of "ctrl_user_id".