Skip to content

Commit b56bf05

Browse files
committed
[Form] render hidden empty inputs for checkboxes
This ensures that a form is always considered submitted even if it contains only checkboxes which all haven't been checked by the user.
1 parent 3f650f8 commit b56bf05

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
{%- endblock choice_widget_options -%}
8686

8787
{%- block checkbox_widget -%}
88-
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
88+
<input type="hidden" name="{{ full_name }}" /><input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
8989
{%- endblock checkbox_widget -%}
9090

9191
{%- block radio_widget -%}

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/checkbox_widget.html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<input type="checkbox"
1+
<input type="hidden" name="<?php echo $view->escape($full_name) ?>" /><input type="checkbox"
22
<?php echo $view['form']->block($form, 'widget_attributes') ?>
33
<?php if (strlen($value) > 0): ?> value="<?php echo $view->escape($value) ?>"<?php endif ?>
44
<?php if ($checked): ?> checked="checked"<?php endif ?>

src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ public function testMultipleChoiceExpandedWithLabelsAsFalse()
805805
/following-sibling::input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
806806
/following-sibling::input[@type="hidden"][@id="name__token"]
807807
]
808-
[count(./input)=3]
808+
[count(./input)=5]
809809
[count(./label)=1]
810810
'
811811
);
@@ -837,7 +837,7 @@ public function testMultipleChoiceExpandedWithLabelsSetByCallable()
837837
/following-sibling::label[@for="name_2"][.="[trans]label.&c[/trans]"]
838838
/following-sibling::input[@type="hidden"][@id="name__token"]
839839
]
840-
[count(./input)=4]
840+
[count(./input)=7]
841841
[count(./label)=3]
842842
'
843843
);
@@ -862,7 +862,7 @@ public function testMultipleChoiceExpandedWithLabelsSetFalseByCallable()
862862
/following-sibling::input[@type="checkbox"][@name="name[]"][@id="name_1"][@value="&b"][not(@checked)]
863863
/following-sibling::input[@type="hidden"][@id="name__token"]
864864
]
865-
[count(./input)=3]
865+
[count(./input)=5]
866866
[count(./label)=1]
867867
'
868868
);

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ public function testMultipleChoiceExpanded()
11331133
/following-sibling::label[@for="name_2"][.="[trans]Choice&C[/trans]"]
11341134
/following-sibling::input[@type="hidden"][@id="name__token"]
11351135
]
1136-
[count(./input)=4]
1136+
[count(./input)=7]
11371137
'
11381138
);
11391139
}
@@ -1160,7 +1160,7 @@ public function testMultipleChoiceExpandedWithoutTranslation()
11601160
/following-sibling::label[@for="name_2"][.="Choice&C"]
11611161
/following-sibling::input[@type="hidden"][@id="name__token"]
11621162
]
1163-
[count(./input)=4]
1163+
[count(./input)=7]
11641164
'
11651165
);
11661166
}
@@ -1189,7 +1189,7 @@ public function testMultipleChoiceExpandedAttributes()
11891189
/following-sibling::label[@for="name_2"][.="[trans]Choice&C[/trans]"]
11901190
/following-sibling::input[@type="hidden"][@id="name__token"]
11911191
]
1192-
[count(./input)=4]
1192+
[count(./input)=7]
11931193
'
11941194
);
11951195
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy