Re:Don’t name your input elements ‘action’ or ‘submit’
by web007 on Wednesday May 07, 2014 @11:40AM
(#7710763)
I've had something like this bite me before. Back in ~2008 one of the browsers introduced support for a new attribute keyword for some HTML element (Maybe "autocomplete"? I wish I could remember.). Since there wasn't one of those defined before, we expando'd it and used the attribute to hook up our functions. When it started to mean something to the browser, it tried to interpret our attribute and freaked out. It took a while to figure out that it was a new feature, but from then on we prefixed $COMPANYNAME_ for all of our attributes.
Re:Don’t name your input elements ‘action’ or ‘submit’
by stronglikedan on Wednesday May 07, 2014 @11:31AM
(#7710707)
I like to prefix the element name with the entity name that will be written to. That way, if I have a form that will be writing to the attributes of multiple entities, I know exactly what each represents. If two entities share an attribute name, then the element names will be distinct. For instance, if I have a UI where the user can enter order details and add order lines, then the elements that represent order attributes are prefixed with "order-" and the others are prefixed with "orderLine-". It is tremendously helpful during maintenance.
Re:Don’t name your input elements ‘action’ or ‘submit’
by dm2 on Wednesday May 07, 2014 @02:48PM
(#7711973)
Yep, that too. "dm2_register_form_name_input" for example. You could probably mix upper/lowercase to format it better but for some reason I don't like to mix them, just personal preference.
I avoid dashes because the text editor I use doesn't select them as a whole word when I double click them.
Re:Don’t name your input elements ‘action’ or ‘submit’
by stronglikedan on Wednesday May 07, 2014 @08:00PM
(#7713287)
Oops, I didn't mean to type "orderLine" in camel case. I usually use underscores in the entity and attribute names, and separate them with a dash, like "order_line-item_sku". That way, I can distinctly select the entity or attribute, or easily search for all attributes for a given entity, like "order_line-".
I normally do a short acronym for my project followed by an underscore for these types of things.
Look at Google's search form, many of their IDs and classes are prepended with "gs_" and others are named something sufficiently unique so that they won't be accidentally repeated or overwritten.
Also, reserved words:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-...
http://php.net/manual/en/reserved.keywords.php
http://www.php.net/manual/en/reserved.variables.php