^Status|Draft|
^Todo|Fill in missing parts, Form_Group! |
====== Forge Module (Form Generation) ======
**This module is no longer distributed with Kohana versions 2.2 or later. This page will be left intact as a courtesy to existing Forge users.**
The Forge module is a module to easily create and manage forms. You can create forms with built-in validation in one go. Forge coexists with the Form helpers, it doesn't replace it. Forge provides help with rendering, validating and filtering forms, the form helper provides methods to create forms.
===== Creating a form =====
Creating a form is done by instantiating the Forge class
$form = new Forge('', 'Add article', 'POST', array('id' => 'article_form'));
This is the start of each form. The Forge class will accept up to four arguments, all of which are optional. The first argument is the form action, the second is the form title, the third argument is the form submittal method, and the last argument is an array of attributes.
Here you see only three arguments being used, the last of which is obviously the attribute array. You can also set any of these attributes after the fact or on the fly by using the method below.
Say we want to change the class and method attribute of the form.
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
==== Adding elements ====
Next step is adding elements.
$form->input('title');
This is the basis of adding elements. Now we set a label and add rules.
$form->input('title')->label(true)->rules('required|length[3,40]|valid_alpha_numeric')->value('title');
==== A complete form ====
$form = new Forge('', 'Add article','POST',array('id' => 'article_form'));
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
$form->input('title')->label(true)->rules('required|length[3,40]|valid_alpha_numeric');
$form->input('article')->label('Article text')->rules('required||valid_alpha_numeric');
$form->submit('submit');
if($form->validate())
{
echo $form->title->value;
echo $form->article->value;
}
else
{
// in Kohana < 2.2
echo $form->html();
// in Kohana 2.2
echo $form->render();
}
==== Form methods ====
=== set_attr() ===
''set_attr()'' set an attribute of the