13

I am building a faceted search system that has inputs in a sidebar (the facets are check boxes), and an input in the header of the page (the main query box). All of these inputs are submitted simultaneously when the user submits a search.

The only way I can think of to make this work is to wrap the entire page in an HTML form tag. Something like the following pseudo-html:

<form>
  <div id='header'>
    <logo/>
    <input id='q'/>
    <!-- a bunch more stuff -->
  </div>
  <div id='sidebar'>
    <div id='sidebar-facets-subsection'>
      <input id='facet1'/>
      <input id='facet2'/>
      <input id='facet3'/>
      <!-- a bunch more stuff -->
    </div>
    <div id='sidebar-form-subsection'>
      <form id='unrelated-form'>
        <input id='unrelated-input-1'/>
        <input id='unrelated-input-2'/>
      </form>
    </div>
  </div>
  <!-- a bunch more stuff -->
</form>

This would work, except for three things:

  1. I need to use other forms in the page, as I've indicated above.
  2. I use different django templates to generate the header and the sidebar, making the templates have dependencies on each other.
  3. It's a real mess since the sidebar is in reality about 100 lines, not three.

Is there a more clever way of doing this that I'm not aware of, or is creating huge HTML forms the norm? In circumstances like this, is it better to use Javascript to somehow generate the input entries in a more normal form? Or is that the only option?

Any creative solutions or ideas?

mlissner
  • 17,359
  • 18
  • 106
  • 169
  • There are a number of studies out that tell you that yes, a single form, aligned left, with the labels on top of each field produces the best completion percentages at the fastest times. Try wrapping fieldsets around groups, and use labels left aligned and on the top of the field that you want to enter the data for. – awm Nov 19 '11 at 02:53
  • 2
    The OP is asking if its okay to wrap the `
    ` element around the entire page, not anything about presentation.
    – Yuji 'Tomita' Tomita Nov 19 '11 at 03:17
  • Thanks @Yuji. Yes, this is not a question about user experience, but rather a technical one about how to handle the HTML/JS. – mlissner Nov 19 '11 at 18:15
  • See also: [How do you overcome the html form nesting limitation](http://stackoverflow.com/questions/597596/how-do-you-overcome-the-html-form-nesting-limitation) – Kevin Stricker Nov 24 '11 at 03:47
  • Is it possible to change your template logic to generate the query box in the *same* logical form as the checkboxes? Then *visually* move the query box into the page header, using CSS relative position offsets? – John C Nov 27 '11 at 13:05
  • @JohnC, yeah, I may end up doing this, but I *really* don't like how it breaks the flow of the page. I think it's probably better to actually move the div with CSS. – mlissner Nov 27 '11 at 17:30
  • @JohnC Sorry - meant to say "move the div with JS"! – mlissner Nov 29 '11 at 23:03

3 Answers3

4

You can make it work with Javascript without sacrifying accesibility

  1. Put all the checkboxes in the header and wrap them in div
  2. Set up and empty but clean side bar
  3. Using Javascript, move you checkboxes from the header into the side bar
  4. Attach a callback to the form.submit event, and when the user submit the form, cancel the event then, take the data from the search field and the checkboxes and send it as an Ajax POST request.

Using a framework like jQuery, it's a 15 minutes job.

If the user has JS enable, the form will post the request and everything will work. If the user doesn't have javascript enable, the checkboxes will be in the header and so they will work, at just the price of a slightly less elegant design.

But people with Javascript disable are used to design changes so it's ok.

Bite code
  • 578,959
  • 113
  • 301
  • 329
  • This sounds pretty clever. I can live with a nasty header for the non-JS people. My only concern now is the checkboxes moving around while the page loads. Is that easily avoided somehow? – mlissner Nov 26 '11 at 18:06
  • Thanks Kevin. I'm increasingly convinced this (or similar) is the way. Who knew HTML could be so tricky? – mlissner Nov 27 '11 at 17:31
3

Use javascript to populate a hidden field with a list of this checkboxes name=value pairs on form submit and treat this in serverside code, spliting the string into an array, etc. Please note that this is not a good aprouch, since you loose accecibility to those with javascript disabled. The form tag is the only accessible way of doing so.

You can try to change the layout, if you can, swaping the checkboxes with links of buttons that filters the data, almost the way most ecommerce sites do out there.

Ricardo Souza
  • 16,030
  • 6
  • 37
  • 69
  • Yeah, accessibility is important, but if I can't build the page at all otherwise, I don't have a lot of options. I need checkboxes so users can change multiple facets in one submission. – mlissner Nov 19 '11 at 18:16
1

I believe you have two options:

1.) a page wide form element. All "submit" buttons submit to the same form and the server-side script processes the form for all filled elements. By page wide, I'm not being literal... The related inputs all in the same form tag. Other forms are placed in other form tags.

2.) multiple forms, with a client side script which populates hidden form fields with the data from the other form before submission.

1 requires more work, but 2 may not work for every visitor.

Do consider the fact that, just because you have one form container, you don't have to necessarily display everything together for the user. Encapsulate inputs in divs and position them according to your will. It may not be easy, but it's definitely possible.

stslavik
  • 2,920
  • 2
  • 19
  • 31