Forum

Thread tagged as: Question, Problem, Field-Types

Checkboxes prevents form from submitting

I have a Perch Form, that has some radio buttons, put together with the help of a repeater like so:

<div class="bookingformdates">
 <perch:input type="radio" id="date" required="true" label="Datum" options="<perch:repeater id="training dates"> <perch:content id="trainingdate" type="date" format="<perch:if id="language" value="en">%m/%d/%Y<perch:else />%d.%m.%Y</perch:if>" /><perch:if exists="contents"> (<perch:content id="contents" />)</perch:if><perch:if id="perch_item_index" match="neq" value="{perch_item_count}">,</perch:if></perch:repeater>" />
</div>
<perch:error for="date" type="required">Please choose a date</perch:error>

That works beautifully.
Now the client wants to enable people to book multiple events at once. So I wanted to change the above to checkboxes.

<perch:repeater id="trainingdates">
 <div class="checkbox">
  <perch:input type="checkbox" id="training<perch:content id="perch_item_index" />" label="Register" value="<perch:content id="trainingdate" type="date" format="%d.%m.%Y" /><perch:if exists="contents"> (<perch:content id="contents" />)</perch:if>"  />
  <span></span>
  <perch:label for="training<perch:content id="perch_item_index" />"><perch:content id="trainingdate" type="date" format="<perch:if id="language" value="en">%m/%d/%Y<perch:else />%d.%m.%Y</perch:if>" /><perch:if exists="contents"> (<perch:content id="contents" />)</perch:if></perch:label>
 </div>
</perch:repeater>

The form doesn't get submitted any longer.
Even if I get rid of the repeater for testing, not sending.

<div class="checkbox">
 <perch:input type="checkbox" id="training123" label="Register" value="IWB"  />
 <span></span>
 <perch:label for="training123">IWB</perch:label>
</div>

When I change back to the radio buttons it works just fine.
Is it me or my code?
Thanks for any hints.

Nils Mielke

Nils Mielke 3 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not sure it's going to work giving the fields a dynamic ID.

Probably. But it won't even submit with the fixed ID as in the last example. I have other checkboxes in that form, that work fine, though. Puzzled

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does debug give you when the form wont submit?

Just found out, what it was:
When I put in the checkboxes to replace the radio buttons, I commented the radio buttons out (in order to be able to revert to the initial functionality without hassle).
It seems, that those parts interfered with the form in such a way, that it didn't send.
Deleting the comments healed the form.

Drew McLellan said:

I'm not sure it's going to work giving the fields a dynamic ID.

The dynamic fields I don't get to work.
Is it possible to have repeaters put checkboxes in a form in any way?
The use case being, that the user should have the possibility to register for multiple events through the form.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Forms don't implement repeaters, no. What does debug give you when the form wont submit?

Do you mean before I deleted the outcommented (is that a word?) radio buttons?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I mean in whatever state you're saying it's not working in.

It says

DIAGNOSTICS:
SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0

Array

(

    [date] => required

)

"date" being the input element, that is commented out. Like so:

<!--<div>
  <perch:label for="date"><perch:if id="language" value="en">Training<perch:else />Schulung</perch:if></perch:label>
  <div class="bookingformdates">
    <perch:input type="radio" id="date" default="" required="true" label="Registered for" options="<perch:repeater id="trainingdates"><perch:content id="trainingdate" type="date" format="<perch:if id="language" value="en">%m/%d/%Y<perch:else />%d.%m.%Y</perch:if>" /><perch:if exists="contents"> (<perch:content id="contents" />)</perch:if><perch:if id="perch_item_index" match="neq" value="{perch_item_count}">,</perch:if></perch:repeater>" />
  </div>
  <perch:error for="date" type="required">Please choose a training</perch:error>
</div>-->
Drew McLellan

Drew McLellan 2638 points
Perch Support

If it's commented out then there's no way for the user to fulfil the validation requirement.

I didn't know the form is trying to process the radio buttons although they are commented out, though.
Lesson learned, I guess.
Thanks, Drew.

Any chance for the repeaters to be processable by a form in the future?

Drew McLellan

Drew McLellan 2638 points
Perch Support

HTML comments don't apply to Perch tags, only to HTML. There's cases where you'd want to manage content within HTML comments - think about IE conditional comments etc.

Makes sense, thanks.