{"success":true,"name":"everything-a-form-sends-is-a-string-convert-and-validate-at-","description":"Reading form or request values and using them as numbers, booleans, or dates directly","category":"ai-brimind","path":"ai-brimind/everything-a-form-sends-is-a-string-convert-and-validate-at-/SKILL.md","file":"SKILL.md","content":"---\nname: everything-a-form-sends-is-a-string-convert-and-validate-at-\ndescription: \"Reading form or request values and using them as numbers, booleans, or dates directly\"\n---\n\n# Everything a Form Sends Is a String: Convert and Validate at the Handler, Not Deep Inside\n\n## When to use\nCode consumes form fields, query parameters, or dataset attributes as if typed, or comparisons against numbers/booleans behave wrongly on submitted data.\n\n## Example request\nage from the form compared with > 18 → it's the string '20', comparison rules surprise you; string math. unchecked checkbox → the field is absent entirely, not false; missing, not negative. query param ?active=false → the string 'false' is truthy; the env-var trap's twin. select value 3 === option id 3 → '3' never equals 3 strictly; type mismatch at the border. — each trusted the wire to deliver types.\n\n## Instructions\nAct as a dock inspector who knows every container arrives labeled 'text' regardless of the manifest. HTML forms, URLs, and data attributes transmit only strings — number inputs yield string digits, date inputs yield string dates, select values are strings even when the options were numbers — and checkboxes don't even send false: an unchecked box is simply absent from the submission, which is the absence-versus-falsy trap wearing a form's clothes. So convert at the border, once: the handler that receives the submission (client or server, per the validation-at-the-door rules) parses each field to its real type — strict numeric conversion per the partial-parse rules, explicit checkbox presence-to-boolean, date parsing per the date rules — and everything past that border handles typed values only, never raw strings sneaking into business logic. The same law covers query parameters and element dataset attributes: all strings, always. Watch the comparison symptom: a strict equality between a submitted value and a number that 'should match' but doesn't is this bug announcing itself — print both values with their types before theorizing. Schema validation per the project's rules does this conversion systematically; use it where it exists. Only proceed once each consumed field crosses exactly one point where its string form dies and its typed form is born.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #820\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}