{"id":22056836,"url":"https://github.com/letsjump/yii-autoactiveform","last_synced_at":"2026-05-10T03:38:21.324Z","repository":{"id":22709039,"uuid":"26053164","full_name":"letsjump/Yii-AutoActiveForm","owner":"letsjump","description":"A quick way to build form fields in Yii, with -rw RBAC access control","archived":false,"fork":false,"pushed_at":"2015-05-01T08:31:30.000Z","size":356,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-28T22:31:01.087Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/letsjump.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":"2014-11-01T14:46:38.000Z","updated_at":"2015-10-04T14:34:46.000Z","dependencies_parsed_at":"2022-07-27T03:17:24.324Z","dependency_job_id":null,"html_url":"https://github.com/letsjump/Yii-AutoActiveForm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsjump%2FYii-AutoActiveForm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsjump%2FYii-AutoActiveForm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsjump%2FYii-AutoActiveForm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letsjump%2FYii-AutoActiveForm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/letsjump","download_url":"https://codeload.github.com/letsjump/Yii-AutoActiveForm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245128744,"owners_count":20565328,"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-11-30T16:14:57.958Z","updated_at":"2026-05-10T03:38:16.300Z","avatar_url":"https://github.com/letsjump.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AutoActiveForm\n\nIn a web full of *complex html form templates*, this extension provides a **faster way to draw fields** in Yii Framework 1.1.\nIt also has an **access control system** in order to give *read / hide / write*  access to every field according to *Yii RBAC Access Rules*.\n\n## Simple example\nthis code\n```php\necho $form-\u003eautoTextField($model, 'Name');\n```\ngenerates this html\n```html\n\u003cdiv class=\"fieldcontainer\"\u003e\n    \u003clabel for=\"Model_name\" class=\"required\"\u003e\n        Oggetto \n        \u003cspan class=\"required\"\u003e*\u003c/span\u003e\n    \u003c/label\u003e\n    \u003cspan class=\"field\"\u003e\n    \t\t\u003cinput name=\"Model[name]\" id=\"Model_name\" type=\"text\" maxlength=\"255\" value=\"\" /\u003e\n    \t\t\u003cspan class=\"errorMessage\" id=\"Model_name_em_\" style=\"display:none\"\u003e\u003c/span\u003e\n    \u003c/span\u003e\n\u003c/div\u003e\n```\nand this code\n```php\necho $form-\u003eautoDatePicker($model,'cr_date');\n```\ngenerates\n```html\n\u003cdiv class=\"fieldcontainer\"\u003e\n\t\u003clabel for=\"Model_cr_date\"\u003eData Creazione\u003c/label\u003e\n\t\u003cspan class=\"field\"\u003e\n\t\t\u003cinput id=\"Model_cr_date\" name=\"Model[cr_date]\" type=\"text\" value=\"05/07/2014\" /\u003e\n\t\t\u003cspan class=\"errorMessage\" id=\"Model_cr_date_em_\" style=\"display:none\"\u003e\u003c/span\u003e\n\t\u003c/span\u003e\n\u003c/div\u003e\n\u003cscript type=\"text/javascript\"\u003e\n/*\u003c![CDATA[*/\njQuery('#Model_cr_date').datepicker(jQuery.extend({showMonthAfterYear:false},jQuery.datepicker.regional['it'],null));\n/*]]\u003e*/\n\u003c/script\u003e\n```\n## Benefits\n+ \tIt extends `CActiveForms` native method so you can invoke any field (like `$form-\u003einputField`, \t`$form-\u003epasswordField`, `$form-\u003echeckbox` and so on...) just adding the `auto` prefix. Example: `$form-\u003etextArea(...)` becomes `$form-\u003eautoTextArea(...)`\n+ \t**It can be extended** so you can add configuration for third party *extension* like **Chosen** or **TinyMce** with just some line of code in your *CustomForm.php* configuration file\n+ \tYou can change configuration **globally** or locally: just **one form** or just **one field**.\n+\tField templates are mastered as normal **Yii view files**\n+ \tYou can also use `CActiveForm` native method, EG: `$form-\u003elabel(...)`, `$form-\u003etextField(...)` and `$form-\u003eerror(...)`\n+ \tA complete **access control** to draw field according with **user permissions**\n\n## Usage\n- \tput AutoActiveForm folder in your *ext* directory\n- \tcopy *CustomForm.php* in your components directory and configure it\n- \tmodify `Yii::import('ext.autoActiveForm.AutoActiveForm')` according to fit the extension's alias path\n- \tcall Yii ActiveForm widget with the path of your custom form:\n```php\n$form=$this-\u003ebeginWidget('application.components.CustomForm',\n\tarray(\n\t...\n\t)\n);\n```\n- \tcall any *CActiveForm field* method adding the `active` prefix\n```php\n$form-\u003eautoTextField($model, 'surname');\n$form-\u003eautoPassword($model, 'pass');\n$form-\u003eautoCheckBox($model, 'yes_no');\n$form-\u003eautoDropDownList($model, ',my_list', Array(1=\u003e'One', 2=\u003e'Two'));\n```\nIn addiction, it is strongly recommended to copy the *view* folder that contains your field template into your *theme* folder and configure `$this-\u003eviewPath` value according to its path:\n ```php\n class CustomForm extends AutoActiveForm\n {\n \tpublic function init() {\n     \t\t$this-\u003eviewPath = 'my.theme.folder.my.autoactiveform-view.folder'\n \t...\n ```\nDoing so, your work will not be deleted after new **AutoActiveForm** plugin releases.\n## Advanced fields configuration\n### Add field HTML options\nAs in CActiveForm you'll pass configurations using `$htmlOptions` array:\n```php\n$form-\u003eautoTextField($model, 'surname', Array('class'=\u003e'oh_my_god', 'style'=\u003e'color: green'));\n```\n### Add label or error HTML options\nIf you need to pass configurations to the *label* or *error* HTML tag, *AutoActiveForm* provides two special array of parameters inside `$htmlOptions`:\n- `labelHtmlOptions` (array)\n- `errorHtmlOptions` (array)\n\nExample:\n```php\n$form-\u003eautoTextField($model, 'gender', Array('labelHtmlOptions'=\u003eArray('class'=\u003e'required'));\n$form-\u003eautoTextField($model, 'age', Array('errorHtmlOptions'=\u003eArray('class'=\u003e'blink'));\n```\n### Additional field configuration settings\nIn addition to `labelHtmlOptions` and `errorHtmlOptions`, you can pass some other array of parameters to `$htmlOptions`:\n- `jsOptions`: \t(array) special options used in complex jQuery fields like TinyMce\n- `roValue`: \t(string) read only value for this field\n- `viewFile`: \t(string) alternative view just for this field\n\n### Form configurations\n*AutoActiveForm* has some special configuration that changes the default behavior:\n- `$viewPath`: \t\t\t(string) path alias to the view's folder\n- `$viewFile`: \t\t\t(string) name of the default view\n- `$accessControl`: \t\t(bool) enable / disable access control\n- `$addHtmlOptions`:\t\t(array) add an array of $htmlOptions to every field of the form\n- `$allowAction`:\t\t\t(string) action to perform when access control is disabled. Usually the action `write` that draw a form field with its label and its error tag\n- `$showLabels`:\t\t\t(bool) enable / disable the label generator. Usually set to false when use placeholder\n- `$labelToPlaceholder`:\t(bool) automatically generates a `placeholder=\"\"` attribute with the label's text for every field\n\n#### Set form configurations globally\nTo set configurations globally, you'll have to act in the `init()` method of your `customForm` class:\n```php\nclass CustomForm extends AutoActiveForm\n{\n\tpublic function init() {\n    \t\t// set here your global configurations\n\t\t\t$this-\u003eformParameterName = your global value\n\t\t\tparent::init();\n    \t}\n    \t...\n    }\n    ...\n}\n```\n\n#### Set form configurations locally (this form)\nTo set a form parameter just for a form, there is an `$autoActiveForm` array to set in its form `$this-\u003ebeginWidget()` configuration:\n```php\n$form=$this-\u003ebeginWidget('application.components.customForm',\n\t\tarray(\n\t\t'id'=\u003e'my-automatic-form',\n\t\t'autoActiveForm'=\u003eArray(\n\t\t\t// add here some configurations just for this form\n\t\t\t'accessControl' =\u003e true,\n\t\t\t...\n\t\t),\n\t\t'enableAjaxValidation'=\u003etrue,\n\t\t'htmlOptions' =\u003e array(\n\t\t\t'class'=\u003e'stdform'),\n\t\t)\n\t);\n```\nIf you also need to add some $htmlOptions to every field of this form, there is a special `addHtmlOptions` parameter:\n```php\n$form=$this-\u003ebeginWidget('application.components.customForm',\n\t\tarray(\n\t\t'id'=\u003e'my-coloured-form',\n\t\t'autoActiveForm'=\u003eArray(\n\t\t\t// add here some configurations just for this form\n\t\t\t'addHtmlOptions'=\u003eArray('class'=\u003e'green_border')\n\t\t),\n\t\t'enableAjaxValidation'=\u003etrue,\n\t\t'htmlOptions' =\u003e array(\n\t\t\t'class'=\u003e'stdform'),\n\t\t)\n\t);\n```\nIn the above example, every field of the generated form will have the html property `class=\"green-border\"` automagically setted.\n## Access Control\nIn order to give access control to the fields, you must create the `getFieldAccessRules()` method in its `CActiveRecord` parent model.\n`getFieldAccessRules()` returns a *multidimensional array* similar to `CActiveRecord`'s `rules()` method.\u003cbr/\u003eThis array is composed by a *key* which is the **RBAC rule** that fields must respect, and the *value* of this key that is a **sub-array** where:\n- the *first* item is a **comma separated list of fields**\n- the *second* item is the **action** that the access control **must run** (usually read / write)\n- the *third* optional item is the **scenario** in which the rule should apply\n```php\nclass myDatabaseTable extends CActiveRecord {\n\t...\n\tpublic function getFieldAccessRules()\n\t{\n\t\treturn Array(\n\t\t\t'guest' =\u003e Array(\n\t\t\t\tArray(\n\t\t\t\t\t'my_field_a, my_field_b',\n\t\t\t\t\t'read',\n\t\t\t\t\t'on' =\u003e 'low-level-scenario'\n\t\t\t\t),\n\t\t\t),\n\t\t\t'staffThatCanDoSomething' =\u003e Array(\n\t\t\t\tArray(\n\t\t\t\t\t'my_field_c, my_field_d, my_field_f',\n\t\t\t\t\t'read',\n\t\t\t\t\t'on' =\u003e 'next-level-scenario'\n\t\t\t\t),\n\t\t\t\tArray(\n\t\t\t\t\t'my_field_a, my_field_b',\n\t\t\t\t\t'write',\n\t\t\t\t\t'on' =\u003e 'next-level-scenario'\n\t\t\t\t),\n\t\t\t\tArray(\n\t\t\t\t\t'my_field_a, my_field_b',\n\t\t\t\t\t'read',\n\t\t\t\t\t'on' =\u003e 'some-other-scenario'\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\t}\n\t...\n}\n```\n### Access Control disclaimer\nWatch out: Even if a field is in *read mode* or in *hide mode*, this **don't prevent** that an advanced user / cracker is **passing parameters** to your action's request, so **YOU ARE ADVICED** to take an appropriate strategy to prevent this, like using model's filters depending on scenario, or *unsetting unused parameters from request* before processing it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletsjump%2Fyii-autoactiveform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fletsjump%2Fyii-autoactiveform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletsjump%2Fyii-autoactiveform/lists"}