Skip to content
Greg Bowler edited this page Feb 28, 2023 · 5 revisions

Built on top of PHP.Gt/Dom, PHP.Gt/DomValidation provides server side HTML form validation of user input. It automatically enforces validation rules defined by web standards, such as required inputs, allowed input ranges, and valid select options, but can be extended to validate custom rules such as password complexity.

Many form validation rules are enforced by the browser on the client side, providing a rich user experience across devices, but these rules can be bypassed and have to be duplicated on the server - but having a DOM document available on the server means the validation rules you've already added to your HTML forms can be enforced automatically without having to replicate any validation logic.

An example of what this looks like in your HTML views:

<form id="example-form" method="post">
	<label>
		<span>Your name</span>
		<input name="name" required />
	</label>
	<label>
		<span>Your email</span>
		<input name="email" type="email" required />
	</label>
	<label>
		<span>Your account ID</span>
		<input name="account" pattern="\S*\d{,3}" />
	</label>
	<label>
		<span>Your nation</span>
		<select name="nation" required>
			<option></option>
			<option>Oceania</option>
			<option>Eurasia</option>
			<option>Eastasia</option>
		</select>
	</label>
	<button>Submit</button>
</form>

To get started, learn about the default validation rules.