{"id":163,"date":"2005-10-27T22:38:00","date_gmt":"2005-10-27T22:38:00","guid":{"rendered":"http:\/\/www.bartbusschots.ie\/blog\/?p=163"},"modified":"2014-08-04T15:07:45","modified_gmt":"2014-08-04T15:07:45","slug":"nice-web-forms-and-not-a-table-in-sight","status":"publish","type":"post","link":"https:\/\/www.bartbusschots.ie\/s\/2005\/10\/27\/nice-web-forms-and-not-a-table-in-sight\/","title":{"rendered":"Nice web forms and not a table in sight!"},"content":{"rendered":"<p>I am well aware that tables for layout are a BAD BAD idea and have stopped using them for such perverted things years ago with just one exception, forms. I started doing my forms in lists because IMO that makes sense but clients were always grumpy when web forms weren&#8217;t layed out in the traditional two column way and short of creating a mess of Divs I always ended up falling back to tables for forms. Not anymore! I&#8217;ve FINALLY found a nice way of doing forms so that the XHTML is simple, elegant and more importantly, semantically correct while still keeping to a nice two column layout.<\/p>\n<p><!--more--><\/p>\n<p>OK, this CSS code comes from the VTIE Portal that I&#8217;m currently working on with the <a href=\"http:\/\/www.vtie.nuim.ie\" title=\"The EVE Research Group Home Page\">EVE Research group<\/a> so that explains the names of some of the style classes. The basic thing is that each form on the site like the login form etc should be contained in a &#8216;box&#8217;, this box should have a title and then within it each bit of data needed from the user should be collected in a row consisting of a label and the form element and they should all be lined up in two columns. To make it easier for people to see what label matches what form element the &#8220;row&#8221; should also have an on-hover element to highlight each line as the mouse moves over it.<\/p>\n<p>Below is the XHTML used:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div id=&quot;page_container&quot;&gt;\r\n&lt;h1&gt;Sample CSS Form&lt;\/h1&gt;\r\n&lt;p&gt;The form below is a sample CSS form for a blog entry on the subject. Please note that this form does not submit anywhere!&lt;\/p&gt;\r\n\r\n&lt;div class=&quot;vtie_form_container&quot;&gt;\r\n &lt;h1 class=&quot;vtie_form_container_title&quot;&gt;Sample Form&lt;\/h1&gt;\r\n\r\n &lt;form name=&quot;studentLoginForm&quot; method=&quot;post&quot; action=&quot;&quot; class=&quot;vtie_form&quot;&gt;\r\n &lt;ul class=&quot;form_element_list&quot;&gt;\r\n  &lt;li&gt;&lt;label for=&quot;tb&quot;&gt;A Text Box&lt;\/label&gt; &lt;input type=&quot;text&quot; name=&quot;tb&quot; id=&quot;tb&quot; \/&gt;&lt;\/li&gt;\r\n  &lt;li&gt;\r\n   &lt;label for=&quot;pwd&quot;&gt;A Password Box&lt;\/label&gt;\r\n   &lt;input type=&quot;password&quot; name=&quot;pwd&quot; id=&quot;pwd&quot; \/&gt;\r\n  &lt;\/li&gt;\r\n  &lt;li&gt;\r\n   &lt;label for=&quot;rdo&quot;&gt;Two radio Buttons&lt;\/label&gt;\r\n   &lt;span id=&quot;rdo&quot;&gt;Yes &lt;input type=&quot;radio&quot; name=&quot;rdo&quot; value=&quot;Yes&quot; \/&gt;\r\n   or No &lt;input type=&quot;radio&quot; name=&quot;rdo&quot; value=&quot;No&quot; \/&gt;&lt;\/span&gt;\r\n  &lt;\/li&gt;\r\n  &lt;li&gt;\r\n   &lt;label for=&quot;ck&quot;&gt;A Check Box&lt;\/label&gt;\r\n   I agree &lt;input type=&quot;checkbox&quot; name=&quot;ck&quot; id=&quot;ck&quot; value=&quot;agree&quot; \/&gt;\r\n  &lt;\/li&gt;\r\n  &lt;li&gt;\r\n   &lt;label for=&quot;ta&quot;&gt;A Text Area&lt;\/label&gt;\r\n   &lt;textarea cols=&quot;20&quot; rows=&quot;3&quot; name=&quot;ta&quot; id=&quot;ta&quot;&gt;&lt;\/textarea&gt;\r\n  &lt;\/li&gt;\r\n  &lt;li&gt;\r\n   &lt;label for=&quot;sl&quot;&gt;A Select List&lt;\/label&gt;\r\n   &lt;select name=&quot;sl&quot; id=&quot;sl&quot;&gt;\r\n    &lt;option value=&quot;-1&quot;&gt; -choose- &lt;\/option&gt;\r\n    &lt;option value=&quot;0&quot;&gt;no&lt;\/option&gt;\r\n    &lt;option value=&quot;1&quot;&gt;yes&lt;\/option&gt;\r\n   &lt;\/select&gt;\r\n  &lt;\/li&gt;\r\n &lt;\/ul&gt;\r\n &lt;p class=&quot;button_bar&quot;&gt;\r\n  &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; class=&quot;submit&quot; \/&gt;\r\n &lt;\/p&gt;\r\n &lt;\/form&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>I think even <a href=\"http:\/\/dave.antidisinformation.com\/\" title=\"Dave Barrett's Blog\">Dave B<\/a> would agree that that is nice simple XHTML that is makes semantic sense and is not over-loaded with divs (like my code used to be when I was new to this whole XHTML+CSS thing).<\/p>\n<p>Now, this obviously doesn&#8217;t DO very much! Below is the CSS which both makes this look good and deals with the layout. You can see this form in action <a title=\"Page with a sample form\" href=\"http:\/\/www.minds.nuim.ie\/~voyager\/linkStore\/blog\/sampleCSSForm\/\">here<\/a> BTW.<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n\/* Generic style information from the start of the *\/\r\n\/* style sheet for the site as a whole, not strictly *\/\r\n\/* related to the example but here for completeness *\/\r\ndiv{\r\n  font-family: arial, sans-serif;\r\n  font-size: 10pt;\r\n  color: #000000;\r\n}\r\np{\r\n  text-align: justify;\r\n}\r\nh1, h2, h3, h4, h5, h6{\r\n  margin: 0px;\r\n  padding: 0px;\r\n  padding-top: 20px;\r\n  color: #000099;\r\n  font-family: verdana, arial, sans-serif;\r\n}\r\nh1{\r\n  font-size: 16pt;\r\n}\r\nul{\r\n  padding-left: 25px;\r\n  list-style-image: url(&quot;li.png&quot;);\r\n}\r\n\r\n\/* The style for the box containing the form, *\/\r\n\/* again not strictly related to the example *\/\r\n\/* but again included for completeness. *\/\r\ndiv.vtie_form_container{\r\n  margin-right: 20%;\r\n  margin-left: 20%;\r\n  margin-top: 40px;\r\n  margin-bottom: 40px;\r\n  padding: 0px;\r\n  padding-bottom: 10px;\r\n  border: 1px solid #000099;\r\n  background-color: #f9f9ff;\r\n}\r\nh1.vtie_form_container_title{\r\n  padding: 2px;\r\n  background-color: white;\r\n  background-image: url(headingBackground.png);\r\n  text-align: center;\r\n  margin-top: 0px;\r\n  margin-bottom: 10px;\r\n  text-transform: uppercase;\r\n  font-size: 12pt;\r\n  border-bottom: 1px solid #BFCAE2;\r\n}\r\n\r\n\/* The code to make the form elements look nice and to *\/\r\n\/* ensure that buttons get the hand pointer (the code for *\/\r\n\/* the cursor is for Firefox only as IE does thing in a *\/\r\n\/* non-standards compliant way). *\/\r\n\/* You should also note that this CSS allowes buttons that *\/\r\n\/* submit the form to be marked to look different to *\/\r\n\/* regular buttons. *\/\r\nform.vtie_form input{\r\n  font-family: Verdana, Arial, sans-serif;\r\n  font-size: 9pt;\r\n  background-color: #D7E5F2;\r\n  color: #000099;\r\n  border: 1px solid #284279;\r\n  margin: 2px;\r\n}\r\nform.vtie_form select{\r\n  font-family: Verdana, Arial, sans-serif;\r\n  font-size: 9pt;\r\n  background-color: #D7E5F2;\r\n  color: #000099;\r\n  border: 1px solid #284279;\r\n  margin: 2px;\r\n}\r\nform.vtie_form textarea{\r\n  font-family: Verdana, Arial, sans-serif;\r\n  font-size: 9pt;\r\n  background-color: #D7E5F2;\r\n  color: #000099;\r\n  border: 1px solid #284279;\r\n  margin: 2px;\r\n}\r\ndiv.vtie_form_container p.button_bar{\r\n  margin-left: 25px;\r\n}\r\nform.vtie_form p.button_bar input{\r\n  cursor: pointer;\r\n}\r\nform.vtie_form p.button_bar input:hover{\r\n  color: black;\r\n}\r\nform.vtie_form p.button_bar input.submit{\r\n  font-weight: bold;\r\n}\r\n\r\n\/* FIANLLY, the code to do the whole two column *\/\r\n\/* thing and to highlight the row being hovered over. *\/\r\nul.form_element_list li{\r\n  clear: both;\r\n  padding: 2px;\r\n}\r\nul.form_element_list li:hover{\r\n  background-color: #FFF;\r\n  border: 1px solid #BFCAE2;\r\n  padding: 1px;\r\n}\r\nul.form_element_list input, ul.form_element_list textarea, ul.form_element_list select{\r\n  margin: 0px;\r\n}\r\nul.form_element_list label{\r\n  display: inline;\r\n  float: left;\r\n  width: 150px;\r\n}\r\n<\/pre>\n<p>As you can see from the comments in the CSS I have included ALL the CSS that relates to the form including the code for the look and feel as well as just the code for the two column layout.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am well aware that tables for layout are a BAD BAD idea and have stopped using them for such perverted things years ago with just one exception, forms. I started doing my forms in lists because IMO that makes sense but clients were always grumpy when web forms weren&#8217;t layed out in the traditional [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[12,16],"tags":[430,432,429],"series":[],"class_list":["post-163","post","type-post","status-publish","format-standard","hentry","category-computers-tech","category-programming","tag-css","tag-html","tag-web-design"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p7t9xK-2D","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/posts\/163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/comments?post=163"}],"version-history":[{"count":1,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/posts\/163\/revisions"}],"predecessor-version":[{"id":7422,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/posts\/163\/revisions\/7422"}],"wp:attachment":[{"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/media?parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/categories?post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/tags?post=163"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/series?post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}