What is it?

Minacl stands for Minacl Is Not A Component Library which gives us a hint to what this library is all about.  Born out of frustration with other form libraries like Zend_Form and Symfony's sfForms, Minacl focuses on creating forms by writing HTML first.

This is the agile part of the framework and it means you don't need to be a PHP developer to customise the look of the forms, an extremely useful benefit if you are working with web designers!  It also means that it is much faster to develop forms in, Minacl focuses on validation and access of the data a form produces and leaves it up to you to write the HTML however you like.  The only prerequisites are that you write your forms as valid XHTML (this is because Minacl needs to parse your form) and that you use a couple of helper functions where you specify the name and id attributes of form elements.

Show me!

The easiest way to describe what the library can do is with a quick example. This example is designed just to give you an idea of the libraries basic features. If you are totally new to the library there are more in-depth and fully explained examples @ the learn by example section.

Your form template (loginTemplate.php)

First define what the form looks like with HTML:

<div>
  <label for="<?php echo $this->id('username')?>">User:</label>
  <input id=<?php echo $this->id('username')?> name="<?php echo $this->name('username')?>" />
</div>
<div>
  <label for="<?php echo $this->id('password')?>">Password:</label>
  <input type="password" id=<?php echo $this->id('password')?> name="<?php echo $this->name('password')?>" />
</div>
 

The "id" and "name" helper functions are to let Minacl know there is data on this form that needs accessing.

Working with the form

Once you have this template defined you can then access it with Minacl like so:

$form = new phForm('login', 'loginTemplate'); // first parameter specifies the name of the POST variable the data is sent back in, second param is the template name
$form->username->setValidator(new phRequiredValidator()); // the username field is required
$form->password->setValidator(new phRequiredValidator()); // as is the password field
$form->bindAndValidate($_POST['user']); // bind the posted data for the form and validate it
if($form->isValid())
{
  // process the login
}
echo $form; // renders the form, with any previous values pre-set

Additional information