{"record":{"id":"4b3d06f14e4228bd","repo":"octobercms/october","slug":"invalid-drop-down-option-key-key-option-keys-ca","errorCode":null,"errorMessage":"Invalid drop-down option key: :key. Option keys can contain only digits, Latin letters and characters _ and -","messagePattern":"Invalid drop-down option key: :key\\. Option keys can contain only digits, Latin letters and characters _ and -","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"warning","filePath":"modules/cms/classes/Snippet.php","lineNumber":299,"sourceCode":"                    )]);\n                }\n\n                return $result;\n            }\n        }\n\n        $options = explode('|', $optionsString);\n\n        $result = [];\n        foreach ($options as $index => $optionStr) {\n            $parts = explode(':', $optionStr, 2);\n\n            if (count($parts) > 1) {\n                $key = trim($parts[0]);\n\n                if (strlen($key)) {\n                    if (!preg_match('/^[0-9a-z-_]+$/i', $key)) {\n                        throw new ValidationException(['snippetProperties' => __(\"Invalid drop-down option key: :key. Option keys can contain only digits, Latin letters and characters _ and -\", ['key'=>$key])]);\n                    }\n\n                    $result[$key] = trim($parts[1]);\n                }\n                else {\n                    $result[$index] = trim($optionStr);\n                }\n            }\n            else {\n                $result[$index] = trim($optionStr);\n            }\n        }\n\n        return $result;\n    }\n\n    /**\n     * dropDownOptionsToString is a helper to convert the an array to a string","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/cms/classes/Snippet.php#L281-L317","documentation":"ValidationException thrown while parsing pipe-separated dropdown options for a snippet property ('key:Label|key2:Label2'). When an option declares a key, that key must match /^[0-9a-z-_]+$/i — digits, Latin letters, underscore and hyphen only. Spaces, dots, colons-in-key, or unicode characters in the key are rejected when the snippet is saved.","triggerScenarios":"Defining `'options' => 'Option One:First|my.key:Second'` on a component/snippet property; authoring snippet property YAML with human-readable labels used as keys; pasting option lists from spreadsheets.","commonSituations":"Theme/plugin authors writing natural-language keys in snippet definitions; machine-generated property files using arbitrary separators; keys containing locale-specific characters.","solutions":["Rewrite keys using only [A-Za-z0-9_-]: 'option-one:First|my-key:Second'.","Keep human text on the label side of the colon (after it), never in the key.","Lint your snippet property definitions with the same regex before shipping."],"exampleFix":"// before — space and dot are illegal in keys\n'options' => 'Option One:First|my.key:Second'\n\n// after — keys use digits, letters, _ and - only\n'options' => 'option-one:First|my-key:Second'","handlingStrategy":"validation","validationCode":"$key = trim(explode(':', $optionStr, 2)[0]);\nif (!preg_match('/^[0-9a-z-_]+$/i', $key)) {\n    // sanitize before saving the snippet definition\n    $key = strtolower(preg_replace('/[^0-9a-zA-Z-_]+/', '-', $key));\n}","typeGuard":null,"tryCatchPattern":"try {\n    $options = Snippet::dropDownOptionsToArray($optionsString);\n} catch (Winter\\Storm\\Exception\\ValidationException $e) {\n    // editor shows the offending :key — fix the definition, no runtime retry\n    return back()->withErrors($e->getErrors());\n}","preventionTips":["Keep option keys machine-safe: lowercase, hyphens/underscores, no spaces.","Put all human-readable text in the label (after the colon).","Lint snippet/component YAML through the key regex in CI."],"tags":["snippet","validation","identifier","dropdown"],"backgroundTag":"invalid-identifier","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}