Mokoala v4.0

§ Handling Forms » Creating a Basic Form

Creating a basic form using the MK_Form class is easy. The below example demonstrates how you would build a form with email and password fields.

$fields = array(
	'email' => array(
		'label' => 'Email',
		'type' => 'text',
		'validation' => array(
			'email' => array(),
			'instance' => array()
		)
	),
	'password' => array(
		'label' => 'Password',
		'type' => 'text',
		'validation' => array(
			'instance' => array(),
		),
		'attributes' => array(
			'type' => 'password'
		)
	),
	'login' => array(
		'type' => 'submit',
		'attributes' => array(
			'value' => 'Login'
		)
	)
);

$form = new MK_Form($fields);

print $form->render();

The above form would have three fields.

  1. The first field is an 'Email' address. It also has validation rules attached to it, the first requiring that if a value is given it must be a valid email address, the second requiring that a value must be given.
  2. The second field would be for a 'Password' and like the Email field would require that a value be given. It also has as 'attributes' field that defines that the fields 'type' is set to 'password' meaning that the input will be hidden.
  3. The third field is a 'submit' field that will submit the form. The field will have the value of 'Login'.

The MK_Form::render() method returns the HTML for the form.

Authenticating Users

Basic Guides

Handling Forms

Social Sign In

Using the Dashboard

Working With Data

levitra online