SID-01784: Searching for Check boxes in Forms
| Status: |
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
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.