Request Validation Plugin docs
The Request Validation Plugin ensures that only valid requests are sent to your server. This is especially valuable for applications that depend on server-side validation.
You can simplify your frontend by removing heavy form validation libraries and relying on oRPC's validation errors instead, since input validation runs directly in the browser and is highly performant.
export function ContactForm() {
const [error, setError] = useState()
const handleSubmit = async (form: FormData) => {
try {
const output = await client.someProcedure(parseFormData(form))
console.log(output)
}
catch (error) {
setError(error)
}
}
return (
<form action={handleSubmit}>
<input name="user[name]" type="text" />
<span>{getIssueMessage(error, 'user[name]')}</span>
<input name="user[emails][]" type="email" />
<span>{getIssueMessage(error, 'user[emails][]')}</span>
<button type="submit">Submit</button>
</form>
)
}
Note
If you find oRPC valuable and would like to support its development, you can do so here.