{"id":37011795,"url":"https://github.com/nixphp/form","last_synced_at":"2026-01-14T01:01:12.767Z","repository":{"id":291109379,"uuid":"976612005","full_name":"nixphp/form","owner":"nixphp","description":"NixPHP Form Plugin for handling forms natively.","archived":false,"fork":false,"pushed_at":"2025-11-27T21:09:28.000Z","size":84,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-29T18:18:13.820Z","etag":null,"topics":["csrf","csrf-protection","framework","nixphp","php","plugin"],"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/nixphp.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-02T12:26:27.000Z","updated_at":"2025-09-28T15:07:52.000Z","dependencies_parsed_at":"2025-05-27T10:18:47.604Z","dependency_job_id":"ae82b73f-c645-4a80-b840-47668bbd2570","html_url":"https://github.com/nixphp/form","commit_stats":null,"previous_names":["phpico/form","nixphp/form"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nixphp/form","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixphp%2Fform","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixphp%2Fform/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixphp%2Fform/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixphp%2Fform/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nixphp","download_url":"https://codeload.github.com/nixphp/form/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixphp%2Fform/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407636,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["csrf","csrf-protection","framework","nixphp","php","plugin"],"created_at":"2026-01-14T01:01:07.980Z","updated_at":"2026-01-14T01:01:12.620Z","avatar_url":"https://github.com/nixphp.png","language":"PHP","readme":"\u003cdiv style=\"text-align: center;\"\u003e\n\n![Logo](https://nixphp.github.io/docs/assets/nixphp-logo-small-square.png)\n\n[![NixPHP Form Plugin](https://github.com/nixphp/form/actions/workflows/php.yml/badge.svg)](https://github.com/nixphp/form/actions/workflows/php.yml)\n\n\u003c/div\u003e\n\n[← Back to NixPHP](https://github.com/nixphp/framework)\n\n---\n\n# nixphp/form\n\n\u003e **Form handling the NixPHP way — minimal, secure, intuitive, extendable.**\n\nThis plugin provides **form memory**, **CSRF protection**, a flexible **Validator system**,\nand a full set of **view helpers** for easy form handling in your NixPHP applications.\n\nEverything is registered automatically and works without configuration.\n\n---\n\n## 📦 Features\n\n* ✔️ **Form input memory** (`memory()`, `memory_checked()`, `memory_selected()`)\n* ✔️ **CSRF protection** via automatic event listener\n* ✔️ **Validator system** with dynamic rule registry\n* ✔️ **Built-in rules:** `required`, `email`, `min`, `max`, `boolean`\n* ✔️ **Custom rules** via `Validator::register()`\n* ✔️ **View helpers** (`error()`, `has_error()`, `error_class()`, `validator()`)\n* ✔️ Automatically integrates into `guard()` and the event system\n* ✔️ Zero configuration — plug and play\n\n---\n\n## 📥 Installation\n\n```bash\ncomposer require nixphp/form\n```\n\nThe plugin registers itself. No additional setup needed.\n\n---\n\n## 🚀 Usage\n\n### 🧠 Form Memory\n\n### `memory($key, $default = null)`\n\nRestores previous user input:\n\n```php\n\u003cinput name=\"email\" value=\"\u003c?= memory('email') ?\u003e\"\u003e\n```\n\n### `memory_checked($key, $value = 'on')`\n\nWorks for checkboxes:\n\n```php\n\u003cinput type=\"checkbox\" name=\"terms\" \u003c?= memory_checked('terms') ?\u003e\u003e\n```\n\n### `memory_selected($key, $expected)`\n\nWorks for selects:\n\n```php\n\u003coption value=\"de\" \u003c?= memory_selected('country', 'de') ?\u003e\u003eGermany\u003c/option\u003e\n```\n\nMemory is powered by `param()` and persists automatically after POST requests.\n\n---\n\n## 🧪 Validation\n\nCreate a Validator and run rules:\n\n```php\nvalidator()-\u003evalidate(request()-\u003egetParsedBody(), [\n    'email'    =\u003e 'required|email',\n    'password' =\u003e 'required|min:8',\n]);\n```\n\nCheck validity:\n\n```php\nif (validator()-\u003eisValid()) {\n    // continue...\n}\n```\n\nCustom messages:\n\n```php\nvalidator()-\u003evalidate($request-\u003egetParsedBody(), [\n    'name' =\u003e 'required|min:3'\n], [\n    'name' =\u003e [\n        'required' =\u003e 'Please enter your name.',\n        'min'      =\u003e 'At least %s characters.'\n    ]\n]);\n```\n\nGet errors:\n\n```php\nvalidator()-\u003egetErrorMessages();\nvalidator()-\u003egetErrorMessage('email');\n```\n\n---\n\n### 🧩 Built-in Validation Rules\n\nThe plugin registers these rules automatically:\n\n```php\nValidator::register('required', fn($val) =\u003e !empty($val), 'Field is required.');\nValidator::register('email', fn($val) =\u003e (bool)filter_var($val, FILTER_VALIDATE_EMAIL), 'Please enter a valid email address.');\nValidator::register('min', fn($val, $p) =\u003e empty($val) || mb_strlen((string)$val) \u003e= (int)$p, 'At least %d characters.');\nValidator::register('max', fn($val, $p) =\u003e empty($val) || mb_strlen((string)$val) \u003c= (int)$p, 'Maximum of %d characters.');\nValidator::register('boolean', fn($val) =\u003e filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) !== null, 'Is not a boolean value.');\n\n### Adding your own rule:\n\n```php\nValidator::register('starts_with', function ($value, $param) {\n    return str_starts_with((string)$value, $param);\n}, \"Value must start with '%s'.\");\n```\n\n---\n\n## 🎨 View Helpers for Errors\n\n### `error($field, Validator $validator)`\n\nOutputs error messages wrapped in `\u003cdiv class=\"error-msg\"\u003e`.\n\n```php\n\u003c?= error('email', $validator) ?\u003e\n```\n\n### `has_error($field, $validator)`\n\nUseful for conditional styling:\n\n```php\n\u003cdiv class=\"\u003c?= error_class('email', $validator) ?\u003e\"\u003e\n```\n\n### `error_class($field, $validator)`\n\nReturns `\"error\"` if the field has validation errors.\n\n### `validator()`\n\nReturns the Validator instance from the container:\n\n```php\n$validator = validator();\n```\n\n### `is_post()`\n\nDetects if the request method is POST.\n\n---\n\n## 🛡️ CSRF Protection\n\nCSRF is enforced automatically for:\n\n* POST\n* PUT\n* DELETE\n\nunless an `Authorization` header exists.\n\nAdd the token to your form:\n\n```php\n\u003cform method=\"post\"\u003e\n    \u003cinput type=\"hidden\" name=\"_csrf\" value=\"\u003c?= csrf()-\u003egenerate() ?\u003e\"\u003e\n\u003c/form\u003e\n```\n\nInvalid tokens immediately trigger a 400 response before controller execution.\n\n---\n\n## 🔍 Internals\n\nThe plugin automatically:\n\n* Registers built-in validator rules via the container\n* Hooks CSRF validation into `Event::CONTROLLER_CALLING`\n* Extends the guard with a CSRF service\n* Provides global view helpers for forms\n* Uses `param()` to manage form memory state\n\nAll without configuration.\n\n---\n\n## 📁 Requirements\n\n* `nixphp/framework` ≥ 0.1.0\n* `nixphp/session` ≥ 0.1.0 (required for CSRF + memory)\n\n---\n\n## 📄 License\n\nMIT License.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixphp%2Fform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnixphp%2Fform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixphp%2Fform/lists"}