diff --git a/models/CustomFieldModel.php b/models/CustomFieldModel.php index 4ebb3c0..cc80aa2 100644 --- a/models/CustomFieldModel.php +++ b/models/CustomFieldModel.php @@ -8,6 +8,9 @@ class CustomFieldModel { private $conn; + // Must match custom_field_definitions.field_type's enum() in the schema. + private const ALLOWED_FIELD_TYPES = ['text', 'textarea', 'select', 'checkbox', 'date', 'number']; + public function __construct($conn) { $this->conn = $conn; @@ -87,6 +90,10 @@ class CustomFieldModel */ public function createDefinition($data) { + if (!in_array($data['field_type'] ?? '', self::ALLOWED_FIELD_TYPES, true)) { + return ['success' => false, 'error' => 'Invalid field_type']; + } + $options = null; if (isset($data['field_options']) && !empty($data['field_options'])) { $options = json_encode($data['field_options']); @@ -129,6 +136,10 @@ class CustomFieldModel */ public function updateDefinition($fieldId, $data) { + if (!in_array($data['field_type'] ?? '', self::ALLOWED_FIELD_TYPES, true)) { + return ['success' => false, 'error' => 'Invalid field_type']; + } + $options = null; if (isset($data['field_options']) && !empty($data['field_options'])) { $options = json_encode($data['field_options']);