/** * called by BasicFunctions::hasFieldsetOnMultiCheckbox() * Check if form has "fieldset" and "legend" to group multiple checkbox buttons. * @return true if has, otherwise, false */ public static function hasFieldsetOnMultiCheckbox($e) { // find if there are radio buttons with same name $children = $e->children(); $num_of_children = count($children); foreach ($children as $i => $child) { if (strtolower(trim($child->attr["type"])) == "checkbox") { $this_name = strtolower(trim($child->attr["name"])); for ($j = $i + 1; $j <= $num_of_children; $j++) { // if there are radio buttons with same name, // check if they are contained in "fieldset" and "legend" elements if (strtolower(trim($children[$j]->attr["name"])) == $this_name) { if (BasicChecks::hasParent($e, "fieldset")) { return BasicChecks::hasParent($e, "legend"); } else { return false; } } } } else { return BasicChecks::hasFieldsetOnMultiCheckbox($child); } } return true; }
/** * Check radio button groups are marked using "fieldset" and "legend" elements * Return: use global variable $is_radio_buttons_grouped to return true (grouped properly) or false (not grouped) */ public static function isRadioButtonsGrouped() { global $global_e; $radio_buttons = array(); foreach ($global_e->find("input") as $e_input) { if (strtolower(trim($e_input->attr["type"])) == "radio") { array_push($radio_buttons, $e_input); } } for ($i = 0; $i < count($radio_buttons); $i++) { for ($j = 0; $j < count($radio_buttons); $j++) { if ($i != $j && strtolower(trim($radio_buttons[$i]->attr["name"])) == strtolower(trim($radio_buttons[$j]->attr["name"])) && !BasicChecks::hasParent($radio_buttons[$i], "fieldset") && !BasicChecks::hasParent($radio_buttons[$i], "legend")) { return false; } } } return true; }