{"id":2612,"date":"2015-01-15T15:59:39","date_gmt":"2015-01-15T21:59:39","guid":{"rendered":"http:\/\/8stars.org\/a\/?p=2612"},"modified":"2015-01-15T15:59:39","modified_gmt":"2015-01-15T21:59:39","slug":"showing-lots-of-options-in-contact-form-7","status":"publish","type":"post","link":"https:\/\/8stars.org\/a\/2015\/01\/15\/showing-lots-of-options-in-contact-form-7\/","title":{"rendered":"Showing lots of options in Contact Form 7"},"content":{"rendered":"<p><a href=\"http:\/\/contactform7.com\/\">Contact Form 7<\/a> is a widely used WordPress plugin that offers a fair amount of flexibility, but I needed for it to do something it didn&#8217;t want to do: I wanted to display a form with <em>a lot<\/em> of options and make it look good. Normally one would do this using radio buttons or a dropdown menu. Because scrolling through long dropdown menus is especially annoying, I opted for radio buttons. But then I wound up with a long blob of radio buttons I wanted something with some structure: columns and headings.<\/p>\n<p>CSS to the rescue. The following is not perfect (there are some limitations on selectors that prevented me from getting as fancy as I wanted), but I consider it a big improvement.<\/p>\n<p>First, use the &#8220;Generate tag&#8221; option to create a radio button. Set an ID for the radio-button set. In this example, it is <code>recipientlist<\/code>. Enable the &#8220;Wrap each item with &lt;label> tag?&#8221; option. This CSS is dependent on the tagging that option produces. You could rewrite this to work the other way, but it&#8217;s friendlier to turn that on anyhow.<\/p>\n<p>Second, create your list of options. You probably want to do this in a text editor, not the CF7 editing window. Organize your options into sections, and insert new lines with section headings where appropriate. Begin each section with the same word&#8211;in the example shown below, I&#8217;m using &#8220;Area&#8221;. If you&#8217;re using <a href=\"http:\/\/contactform7.com\/selectable-recipient-with-pipes\/\">piped options<\/a>, it doesn&#8217;t matter what comes after the pipe for these section headings. Paste your completed list into the &#8220;Choices&#8221; field<\/p>\n<p>Third, gank the following CSS:<\/p>\n<pre><code>&lt;style&gt;#recipientlist {\ndisplay: block;\n-webkit-columns: 3 150px;\n-moz-columns: 3 150px;\ncolumns: 3 200px;\n}\n#recipientlist .wpcf7-list-item {\ndisplay: block;\nmargin: .25em 0;\n}\n.wpcf7-list-item input[value^=Area] {\ndisplay: none;\n}\n.wpcf7-list-item input[value^=Area] + .wpcf7-list-item-label {\nfont-weight: bold;\n}&lt;\/style&gt;\n<\/code><\/pre>\n<p>and paste that right into the CF7 &#8220;Form&#8221; field, right at the top. Change <code>#recipientlist<\/code> to whatever ID you are using for your button set. Change <code>Area<\/code> to whatever you are using as the lead-in text for your section headings. Do not introduce any extra line breaks into this, as WordPress will add tags that you don&#8217;t want. Do not try inserting this into your theme&#8217;s styles.css document or via other style-injecting mechanisms, as parts of this will get overridden and you will be sad.<\/p>\n<p>Your radio-button tag should look something like this:<\/p>\n<p><code>[radio recipient id:recipientlist use_label_element *lots of options follow*\u00e2\u20ac\u00a6]<\/code><\/p>\n<p>Copy that code and paste it wherever you think it belongs in your form. The <code>style<\/code> element should be at the top though.<\/p>\n<p>You may want to play around with the number and width of columns, depending on your theme and the content you&#8217;re presenting.<\/p>\n<p>Here&#8217;s a before and after.<\/p>\n<p>Before:<br \/>\n<img decoding=\"async\" src=\"\/a\/content\/badformat.png\" alt=\"before\" \/><\/p>\n<p>After:<br \/>\n<img decoding=\"async\" src=\"\/a\/content\/goodformat.png\" alt=\"after\" \/><\/p>\n<p>This isn&#8217;t perfect&#8211;there&#8217;s no way to control where the column breaks occur, or to show the sections as blocks of equal height. And it&#8217;s not semantically correct HTML. But it&#8217;s an improvement.<\/p>\n<p>[Nerd mode=on]<br \/>\nThere are four CSS rules here. The first one forces the set of buttons to show as a separate line, and breaks it into columns. The second forces each button to display on its own line. The third picks up buttons that begin with the section-identifying word &#8220;Area&#8221;; hiding the radio button and setting some margins. The fourth styles the label text for those section heading buttons.<br \/>\n[Nerd mode=off]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using CSS to impose order on long lists.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[15],"tags":[124,132,268,484],"class_list":["post-2612","post","type-post","status-publish","format-standard","hentry","category-net-stuff","tag-contact-form-7","tag-css","tag-lists","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/8stars.org\/a\/wp-json\/wp\/v2\/posts\/2612","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/8stars.org\/a\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/8stars.org\/a\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/8stars.org\/a\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/8stars.org\/a\/wp-json\/wp\/v2\/comments?post=2612"}],"version-history":[{"count":0,"href":"https:\/\/8stars.org\/a\/wp-json\/wp\/v2\/posts\/2612\/revisions"}],"wp:attachment":[{"href":"https:\/\/8stars.org\/a\/wp-json\/wp\/v2\/media?parent=2612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/8stars.org\/a\/wp-json\/wp\/v2\/categories?post=2612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/8stars.org\/a\/wp-json\/wp\/v2\/tags?post=2612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}