{"id":15649308,"url":"https://github.com/bramstroker/zf2-form","last_synced_at":"2025-08-20T16:31:38.542Z","repository":{"id":5618484,"uuid":"6826145","full_name":"bramstroker/zf2-form","owner":"bramstroker","description":"ZF2 module for extending forms with live clientside validation without need to write js validation code","archived":false,"fork":false,"pushed_at":"2020-11-13T17:52:41.000Z","size":335,"stargazers_count":39,"open_issues_count":9,"forks_count":23,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-12-10T02:20:27.263Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bramstroker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-23T10:56:08.000Z","updated_at":"2022-12-08T23:49:08.000Z","dependencies_parsed_at":"2022-08-24T13:39:37.695Z","dependency_job_id":null,"html_url":"https://github.com/bramstroker/zf2-form","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramstroker%2Fzf2-form","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramstroker%2Fzf2-form/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramstroker%2Fzf2-form/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramstroker%2Fzf2-form/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bramstroker","download_url":"https://codeload.github.com/bramstroker/zf2-form/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230438185,"owners_count":18225870,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T12:29:11.600Z","updated_at":"2024-12-19T13:07:30.604Z","avatar_url":"https://github.com/bramstroker.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StrokerForm\n\n[![Build Status](https://travis-ci.org/bramstroker/zf2-form.png?branch=master)](https://travis-ci.org/bramstroker/zf2-form)\n[![Coverage Status](https://coveralls.io/repos/bramstroker/zf2-form/badge.png)](https://coveralls.io/r/bramstroker/zf2-form)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/bramstroker/zf2-form/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/bramstroker/zf2-form/?branch=master)\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/ee332161-bb3b-401b-bbce-f8572558e998/mini.png)](https://insight.sensiolabs.com/projects/ee332161-bb3b-401b-bbce-f8572558e998)\n[![Total Downloads](https://poser.pugx.org/stroker/form/downloads.svg)](https://packagist.org/packages/stroker/form)\n[![HHVM Status](http://hhvm.h4cc.de/badge/stroker/form.png)](http://hhvm.h4cc.de/package/stroker/form)\n\nZF2 module for extending forms with live clientside validation without need to write js validation code. \nYou only need to define your validation rules server side with ZF2 and this module automaticaly adds the same rules with [jQueryValidate](http://docs.jquery.com/Plugins/Validation). \nIn case a client side version of the validation rule doesn't exist a fallback is done using ajax.\nFor basic usage examples see the sandbox project [StrokerFormSandbox](https://github.com/bramstroker/zf2-form-sandbox).\n\n## BC Breaks since 1.0.0\n\n- Support for PHP versions lower than 5.6 is dropped.\n- `StrokerForm\\Renderer\\JqueryValidate\\Rule\\RuleInterface` has been extended with a new method `canHandle`. This method is called on a rule to check if it can process a certain validator. When you have some custom rules you'll need to update them to implement this new method.\n\n## BC Breaks since 0.1.0\n\nFor the new version you need to copy `config/strokerform.global.php.dist` to your projects `config/autoload` dir.\n\n## Installation\n\nInstallation of StrokerForm uses composer. For composer documentation, please refer to\n[getcomposer.org](http://getcomposer.org/).\n\n  1. `cd my/project/directory`\n  2. create or modify the `composer.json` file within your ZF2 application file with\n     following contents:\n\n     ```json\n     {\n         \"require\": {\n             \"stroker/form\": \"*\"\n         }\n     }\n     ```\n  3. install composer via `curl -s https://getcomposer.org/installer | php` (on windows, download\n     https://getcomposer.org/installer and execute it with PHP). Then run `php composer.phar install`\n  4. open `my/project/directory/configs/application.config.php` and add the following key to your `modules`:\n\n     ```php\n     'StrokerForm',\n     ```\n  6. copy the file `config/strokerform.global.php.dist` from `vendor\\stroker\\zf2-form` to your projects `config/autoload` directory and rename it to `strokerform.global.php`.\n  5. copy the assets to your public folder (my/project/directory/public).\n\n## Usage\n\nFirst we need to make sure jquery is loaded by our application and the headScript() and inlineScript() view helpers are called. If you already have this in place you can skip this step.\n\n```html\n\u003chead\u003e\n  \u003c?php echo $this-\u003eheadLink() ?\u003e\n\t\u003c?php echo $this-\u003eheadScript()-\u003eprependFile('//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js') ?\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cdiv class=\"container\"\u003e\n\t\u003c?php echo $this-\u003econtent; ?\u003e\n\u003c/div\u003e\n\u003c?php echo $this-\u003einlineScript() ?\u003e\n\u003c/body\u003e\n```\n\nFor the ajax validation to work inputfilters needs to be hooked to the form.\nWe need to create a serviceFactory and register it with a unique alias to the formManager (this is an pluginManager).\nIf the inputFilters are already set to the form (i.e. in your form constructor) it's enough to register the form as an invokable\n\n```php\n\u003c?php\nnamespace MyProject\\Service;\n\nuse Zend\\ServiceManager\\ServiceLocatorInterface;\n\nclass MyFormFactory implements \\Zend\\ServiceManager\\FactoryInterface\n{\n    public function createService(ServiceLocatorInterface $serviceLocator)\n    {\n        $form = new MyForm();\n        $model = new MyModel();\n        $form-\u003esetInputFilter($model-\u003egetInputFilter());\n        return $form;\n    }\n}\n```\n\nNow let's add our new factory to the formManager.\n\n```php\n\u003c?php\nreturn array(\n    'stroker_form' =\u003e array(\n        'forms' =\u003e array(\n            'factories' =\u003e array(\n                'my_form_alias' =\u003e 'MyProject\\Service\\MyFormFactory'\n            )\n        )\n    )\n);\n```\n\nLast thing we need to do is invoking the StrokerFormPrepare view helper where you are rendering your form.\nThis view helper add all the needed javascripts to the headScript view helper\n\n```php\n\u003c?php\n$this-\u003estrokerFormPrepare('my_form_alias');\n\n// Do your normal form rendering here\n```\n\n## Renderers\n\nA renderer should implement the RendererInterface and is responsible for modifying the form rendering (setting inline javascript, modifying the form element attributes, view helpers etc.). \nCurrently only the jqueryValidate renderer is available. Support for other validation libraries can be implemented as a seperate renderer. \n\n### JqueryValidate\n\n#### Options\n\n- `include_assets`: Whether you want the view helper to include the needed assets or you like to do it yourself using a asset manager\n- `use_twitter_bootstrap`: Set this to true if you are using twitter bootstrap. \n- `validate_options`: Options for the jquery validate plugin. See [jqueryValidate options](http://docs.jquery.com/Plugins/Validation/validate#toptions) for all possible options. i.e. if you also want to validate on keypress you can set onkeyup to true.\n- `disable_ajax_fallback`: Disables AJAX fallback for non available client side validators\n\n#### Styling\n\nIf you are using twitter bootstrap and the recommended form structure the styling works out of the box. \nWhen you are using the ZF2 view helpers for your form you could style the input fields `error` and `valid` classes which are added on the fly by the jquery plugin.\n\n## Excluding elements from clientside validation\n\nYou can set the option `strokerform-exclude` on a form element\n\n```php\n$name = new Element('name');\n$name-\u003esetLabel('Your name');\n$name-\u003esetOption('strokerform-exclude', true);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbramstroker%2Fzf2-form","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbramstroker%2Fzf2-form","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbramstroker%2Fzf2-form/lists"}