{"issue":{"pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"state":"open","user":{"avatar_url":"https://secure.gravatar.com/avatar/290cdad0e6ff9caf01ca06f70cddc808?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"290cdad0e6ff9caf01ca06f70cddc808","url":"https://api.github.com/users/dragoonis","login":"dragoonis","id":146321},"milestone":{"state":"open","open_issues":11,"url":"https://api.github.com/repos/dragoonis/ppi-framework/milestones/1","due_on":null,"description":"This will include:\r\nthe new PPI_Request components\r\nunit testing","creator":{"avatar_url":"https://secure.gravatar.com/avatar/290cdad0e6ff9caf01ca06f70cddc808?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"290cdad0e6ff9caf01ca06f70cddc808","url":"https://api.github.com/users/dragoonis","login":"dragoonis","id":146321},"number":1,"title":"0.9.1","closed_issues":7,"created_at":"2011-06-08T00:12:08Z"},"assignee":null,"labels":[{"name":"task","color":"FFB440","url":"https://api.github.com/repos/dragoonis/ppi-framework/labels/task"}],"updated_at":"2011-11-01T18:58:20Z","comments":22,"closed_at":null,"url":"https://api.github.com/repos/dragoonis/ppi-framework/issues/44","body":"**The Purpose**\r\n\r\n* To automate the tedious rendering of form elements and the validation of those elements upon submit in JS and PHP land.\r\n\r\n* To allow designers to properly design the forms while still retaining PHP automation and control.\r\n\r\n**The Implementation**\r\n\r\nThis is split up into two parts, we have a backend PHP side and a frontend PHP/HTML side.\r\n\r\n**The Backend Implementation**\r\n\r\n* To init your form\r\n\r\n* To optionally set defaults form for prepopulation\r\n\r\n``` php\r\n<?php\r\n// Init\r\n$form = new PPI_Form(array(\r\n    'name' => 'user_register'\r\n    'method' => 'post'\r\n));\r\n\r\n// Shorthand init\r\n$form = new PPI_Form('user_register', 'post');\r\n\r\n// If we have default values, i.e; we're in Edit Mode and want to pre-populate fields\r\nif($edit) {\r\n    $form->setDefaults(array(\r\n        'username' => 'ppi',\r\n        'country'  => 'uk'\r\n    ));\r\n}\r\n\r\n// Load our template, pass in a $form variable\r\n$this->render('user/register', array('form' => $form->getRenderData());\r\n```\r\n\r\n**The Frontend Implementation**\r\n\r\n* The ability to render form fields, and for them to be automatically pre-populated with the data of the above $form->setDefaults() call.\r\n\r\n* The ability to show errors against each element on the form.\r\n\r\n\r\n``` php\r\n\r\n<?php if($form->hasError('username'): ?>\r\n<div><?php echo $form->getError('username'); ?></div>\r\n<?php endif; ?>\r\n<div><?php echo $form->create('text', 'username'); ?></div>\r\n\r\n<?php if($form->hasError('username'): ?>\r\n<div><?php echo $form->getError('dropdown'); ?></div>\r\n<?php endif; ?>\r\n<div><?php echo $form->create('dropdown', 'language'); ?></div>\r\n```\r\n\r\n\r\n**Defining Form Rules**\r\n\r\nYou define your rules when you create your form, those rules are carried on through to the View layer. If there is a rule for field name \"username\" and you happen to render a form element with the name \"username\" then that rule will activate.\r\n\r\nRules could be manually set into the form object, or you can specify a filename for it to parse for the rules. Depending on the file extension it could parse it differently, i.e  a .ini file or .yaml file.\r\n\r\n```php\r\n<?php\r\n$form = new PPI_Form('user_register');\r\n\r\n// Single Rule\r\n$form->setRule('username', 'rule data to be defined');\r\n\r\n// Multiple Rules \r\n$form->setRules($userModel->getRegisterRules()); // Manual Array\r\n$form->setRulesFromFile('/path/to/rules.ini'); // From External INI File\r\n$form->setRulesFromFile('/path/to/rules.yaml'); // From External YAML File\r\n\r\n```\r\n\r\n**Registering Form Helpers**\r\n\r\nAdding a form helper should be as simple as\r\n\r\n```php\r\n<?php\r\n$form = new PPI_Form('user_register');\r\n$form->addHelper('someHelper', new APP_Helpers_Form_SomeHelper());\r\n\r\n// And then on the front end we can call a helper like so:\r\n$someHelperValue = $form->getHelper('someHelper')->getSomeValue();\r\n\r\n\r\n","html_url":"https://github.com/dragoonis/ppi-framework/issues/44","number":44,"title":"PPI_Form Module","id":1163672,"created_at":"2011-07-04T18:54:39Z"},"action":"created","comment":{"user":{"avatar_url":"https://secure.gravatar.com/avatar/63c59020e0d7efaef816653c853ecc05?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"63c59020e0d7efaef816653c853ecc05","url":"https://api.github.com/users/alganet","login":"alganet","id":202642},"updated_at":"2011-11-01T18:58:20Z","url":"https://api.github.com/repos/dragoonis/ppi-framework/issues/comments/2594315","body":"Seems nice, i like it.","id":2594315,"created_at":"2011-11-01T18:58:20Z"}}