dev-master
9999999-devSimple form generator for Kohana, using PHPTAL templates.
The Requires
dev-develop
dev-developSimple form generator for Kohana, using PHPTAL templates.
The Requires
Simple form generator for Kohana, using PHPTAL templates.
You'll need the KOtal module, as the views are written in PHPTAL., (*1)
Here's a contact form, demonstrating each form element., (*2)
class Konform_Contact extends Konform { /** * Action (location) to submit the form to. * * @var string */ protected $_action = '/contact'; /** * Other attributes (name => value) to apply to the form. * * @var array */ protected $_attributes = array( 'id' => 'something' 'class' => 'konform contact', ); /** * Fields, keyed on their name, with label, rules, type, and other options. * * @var array */ protected $_fields = array( // Simple text entry box. 'name' => array( 'type' => 'text', 'label' => 'Your name', 'maxlength' => 60, 'required' => true, 'rules' => array('not_empty'), ), // One with more validation on it, and a custom CSS class applied to the container. 'email' => array( 'type' => 'text', 'label' => 'Your email address', 'required' => true, 'rules' => array('not_empty', 'email'), 'class' => 'email', ), // Example of a select element. 'group' => array( 'type' => 'select', 'label' => 'Person or group', 'required' => true, 'rules' => array('not_empty'), 'placeholder' => 'Please select...', 'optionSource' => '_getGroups', 'optionValue' => 'pk', 'optionLabel' => 'name', ), // And a textarea. 'body' => array( 'type' => 'textarea', 'label' => 'Your message', 'required' => true, 'rules' => array('not_empty'), 'cols' => '70', 'rows' => '10', ), // Don't forget to add a submit button. 'submit' => array( 'type' => 'submit', 'label' => 'Submit', 'class' => 'buttons' ), ); /** * Get the groups for the dropdown list. * * These source methods must return something iterable (suitable for reading * by foreach - arrays, Iterators, etc). * * @return Database_Result */ protected function _getGroups() { return ORM::factory('group')->find_all(); } }
And, here's the controller code to go with it., (*3)
public function action_index() { $contactForm = new Konform_Contact($this->request->post()); if ($this->request->post() && $contactForm->validate()) { // Looks like we received valid data, so send the emails. $this->_sendContactEmail($contactForm->data()); HTTP::redirect('/contact/thank-you'); } $this->response->body($contactForm->render()); }
Simple form generator for Kohana, using PHPTAL templates.
Simple form generator for Kohana, using PHPTAL templates.