Tags:
create new tag
view all tags

SID-01784: Searching for Check boxes in Forms

Status: Answered Answered TWiki version: 5.1.4 Perl version:
Category: CategoryRendering Server OS: Last update: 12 years ago

I am trying to create a form in which a user can select multiple items via check boxes. I have used the "Contact Form" example as a base for codes. However, it does not include an example for use of check boxes.

Based on the code for a drop-down menu, I believe I am close with this:

<input name="Cheese"> <value></value> %SEARCH{ "\|Cheese.*checkbox" type="regex" topic="JKContactForm" multiple="on" nonoise="on" seperator="," format=">>$percntCALC{$LISTJOIN($sp, $LISTMAP(<value>$item</value> , $TRIM($pattern(.*?select[^\|]*\|[^\|]*\|[ ,]*([^\|]*).*))))}$percnt<<" }% </input>

Instead, it shows as an empty textbox

-- Jordan Kruger - 2013-08-12

Discussion and Answer

You probably meant separator, not seperator.

Do this, assuming you have a checkbox called "Categories" in your form:

%CALC{$LISTJOIN($sp, $LISTMAP(<label><input type="checkbox" name="Categories" value="$item" /> $item </label>%BR%, %SEARCH{
 "\| *Categories "
 type="regex"
 topic="KnowledgeBaseForm"
 multiple="on"
 nonoise="on"
 format="$pattern(\| *Categories .* checkbox[^\|]*\|[^\|]*\| *([^\|]+?) *\|.*)"
}%))}% <input type="hidden" name="Categories" value="" />

The last hidden input field is needed so that all unchecked can be submitted as well.

-- Peter Thoeny - 2013-08-12

FYI, the upcoming TWiki release makes this much easier, as simple as this:

%EDITFORMFIELD{ "Categories" form="MyForm" }%

-- Peter Thoeny - 2013-08-12

This worked, thanks for your help!

-- Jordan Kruger - 2013-08-13

      Change status to:
ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
SupportForm
Status Answered
Title Searching for Check boxes in Forms
SupportCategory CategoryRendering
TWiki version 5.1.4
Server OS

Web server

Perl version

Browser & version

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2013-08-13 - JordanKrew
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.