diff --git a/src/FuzeWorks/Forms/Fields/RadioField.php b/src/FuzeWorks/Forms/Fields/RadioField.php index 4d3f58d..33b5946 100644 --- a/src/FuzeWorks/Forms/Fields/RadioField.php +++ b/src/FuzeWorks/Forms/Fields/RadioField.php @@ -75,6 +75,9 @@ class RadioField extends Field */ public function addOptions(array $options): self { + if (!$this->_isAssoc($options)) + throw new InputException("Could not add options. Options must be provided as an associative array [name => label]"); + foreach ($options as $key => $val) $this->addOption($key, $val); @@ -134,4 +137,16 @@ class RadioField extends Field $out .= ""; return $out; } + + /** + * Internal method for addOptions() + * + * @param array $arr + * @return bool + */ + private function _isAssoc(array $arr): bool + { + if (array() === $arr) return false; + return array_keys($arr) !== range(0, count($arr) - 1); + } } \ No newline at end of file