public function grouped_checkbox($name, $tag_value, $html_attributes = array()) { $values = $this->get_model_data($name); $name = substr($name, -2, 2) == '[]' ? $name : $name . '[]'; $checked = is_array($values) ? in_array($tag_value, $values) : $tag_value == $values; $id = FormTagHelper::sanitize_id($name) . '_' . FormTagHelper::sanitize_id($tag_value); $html_attributes = array_merge(array('id' => $id), $html_attributes); return FormTagHelper::checkbox_tag($this->get_field_name($name), $tag_value, $checked, $html_attributes); }
public function test_sanitize_id() { $this->assertEquals('foo', FormTagHelper::sanitize_id('foo'), 'Standard name'); $this->assertEquals('foo_name', FormTagHelper::sanitize_id('foo[name]'), 'Name with subscript'); $this->assertEquals('foo', FormTagHelper::sanitize_id('foo[]'), 'Name with empty subscript'); $this->assertEquals('foo_Bar_name', FormTagHelper::sanitize_id('foo[Bar][name]'), 'Name with multiple subscripts'); }