checkboxes as required field?

77 views
Skip to first unread message

raspi

unread,
Oct 22, 2015, 4:03:06 PM10/22/15
to php-bootstrap-form
Is there a way to have a checkbox as required?

I tested also this, but it does not validate.

Form::Checkbox("Bestätigung:", "check", array(
"check"=>"Yes, I checked my input")
, array("required" => 1));


Alexander Butenko

unread,
Oct 22, 2015, 4:24:57 PM10/22/15
to php-bootstrap-form
Please try following patch and add a checkbox with a 'required' attribute.
diff --git a/PFBC/Element/Checkbox.php b/PFBC/Element/Checkbox.php
index eafd378..1626041 100644
--- a/PFBC/Element/Checkbox.php
+++ b/PFBC/Element/Checkbox.php
@@ -24,7 +24,7 @@ class Element_Checkbox extends OptionElement {
                        $value = $this->getOptionValue($value);
 
                        echo '<label class="', $labelClass, '">';
-            echo '<input id="', $this->_attributes["id"], '-', $count, '"', $this->getAttributes(array("id", "class", "value", "checked", "required")), ' value="', $this->filter($value), '"';
+            echo '<input id="', $this->_attributes["id"], '-', $count, '"', $this->getAttributes(array("id", "class", "value", "checked")), ' value="', $this->filter($value), '"';
                        if(in_array($value, $this->_attributes["value"]))
                                echo ' checked="checked"';
                        echo '/> ', $text, ' </label> ';

raspi

unread,
Oct 22, 2015, 4:37:21 PM10/22/15
to php-bootstrap-form
OK - Yes
This patch helped.

Now it works fine with the syntax I posted in my original message.
Thanks a lot for this quick help.

Alexander Butenko

unread,
Oct 22, 2015, 11:04:45 PM10/22/15
to php-bootstrap-form
Pushed to the master
Reply all
Reply to author
Forward
0 new messages