Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Blesta uses the Input component to perform automatic error checking and error message handling. The way it works is by defining a set of rules and validating input based on those rules. The Input component is a simple, yet powerful way to validate input. As we'll see, input can even be formatted prior to validation and/or after validation. during validation, either immediately before or after the rule is executed.

Boolean Rules

Boolean rules are the simplest rules of all. Setting the rule to true will always pass validation. Similarly, setting the rule to false will always fail validation.

Code Block
languagephp
titleBoolean Rules
<?php
	...
	$rules = array(
		'field_1' => array(
			'empty' => array(
				'rule' => true,
				'message' => "This error will never be displayed"
			)
		),
		'field_2' => array(
			'valid' => array(
				'rule' => false,
				'message' => "This error will always be displayed" 
			)
		)
	);
	$this->Input->setRules($rules);
?>

Built-in Rules

The Input component has a set of built in rules. The syntax for invoking these rules is a string or a single dimensional array.

...