codaxis / cakephp-parsley-helper
CakePHP Form Helper for Parsley.js automatic validation integration
Installs: 105
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 4
Forks: 2
Type:cakephp-plugin
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-10-26 17:04:30 UTC
README
DEPRECATION WARNING: This plugin is not maintained anymore.
CakePHP Form Helper for Parsley.js automatic validation integration
This helper will automatically read validation rules from active form model and assign field attributes accordingly.
Compatible with Cake 2.4.7+
Feel free to make any code/docs contributions or post any issues.
Basic usage
-
Enable the helper plugin in your app/Config/bootstrap.php by doing
CakePlugin::load('ParsleyHelper');
- or justCakePlugin::loadAll();
. -
Load helper in your
app/Controller/AppController.php
. You can use the classname option if you want to keep your helper alias as "Form".// In AppController.php public $helpers = array('ParsleyHelper.ParsleyForm'); // or public $helpers = array('Form' => array('className' => 'ParsleyHelper.ParsleyForm'));
-
Enable Parsley rules integration in any form by setting
parsley => true
ordata-parsley-validate => true
in Form->create() options array.echo $this->Form->create('MyModel', array('parsley' => true));
-
That's all! When you create an input field, parsley attributes will be set according to the defined validation rules.
Trait usage
If you are running PHP 5.4 or greater, and already using a custom or vendor form helper, you can make use of provided ParsleyFormTrait
and retain both helper functionalities. You can do so by creating a custom helper in your app/View/Helper
folder like this:
// In app/View/Helper App::uses('ParsleyFormTrait', 'ParsleyHelper.View/Helper'); class MyFormHelper extends VendorFormHelper { use ParsleyFormTrait; }