# Bước 1: tạo mảng inputs (ok)

![](https://3988971916-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LXUV09EJOZ8BKB8YL5I%2F-M43-yQy1EWsxlW9fCN5%2F-M430-R_bcezrd960oaD%2FScreenshot_1.png?alt=media\&token=943aabe8-42cc-42ea-94f5-7b4fd5728291)

Chúng ta phải xây dụng được mảng email, mảng password như sau

```
array (
  'email' => 
  array (
    'type' => 'text',
  ),
  'password' => 
  array (
    'type' => 'password',
  )
)
```

Xây dựng class form

```
<?php  
	class Form {
		private $model = 'Model';
		protected $rules = null;
		public $inputs = array();
		public function setRules($rules) {
			if (!empty($rules)) {
				$this->rules = $rules;
				foreach ($rules as $field => $rule) {
					if (isset($rule['form'])) {
						$this->inputs[$field] = $rule['form'];
					}
				}
			}
		}
	};
	$rules = array(
			"email" => array(
				"form" => array(
					"type" => "text"
				), 
				"notEmpty" => array(
					"rule" => "notEmpty", 
					"message" => 'MSG_ERR_NOTEMPTY'
				), 
				"isEmail" => array(
					"rule" => "email", 
					"message" => 'MSG_ERR_EMAIL'
				)
			), 
			"password" => array(
				"form" => array(
					"type" => "password"
				), 
				"notEmpty" => array(
					"rule" => "notEmpty", 
					"message" => 'MSG_ERR_NOTEMPTY'
				)
			), 
			"fullname" => array(
				"form" => array(
					"type" => "text"
				), 
				"notEmpty" => array(
					"rule" => "notEmpty", 
					"message" => 'MSG_ERR_NOTEMPTY'
				)
			), 
			"address" => array(
				"form" => array(
					"type" => "textarea"
				), 
				"notEmpty" => array(
					"rule" => "notEmpty", 
					"message" => 'MSG_ERR_NOTEMPTY'
				)
			)
		);
	$form = new Form();
	$form->setRules($rules);
	echo '<pre>';
		var_export($form->inputs);
	echo '</pre>';
	// array (
	//   'email' => 
	//   array (
	//     'type' => 'text',
	//   ),
	//   'password' => 
	//   array (
	//     'type' => 'password',
	//   ),
	//   'fullname' => 
	//   array (
	//     'type' => 'text',
	//   ),
	//   'address' => 
	//   array (
	//     'type' => 'textarea',
	//   ),
	// )
?>
```

