{"id":22477559,"url":"https://github.com/maplephp/form","last_synced_at":"2025-10-24T18:10:11.451Z","repository":{"id":209873551,"uuid":"610834369","full_name":"MaplePHP/Form","owner":"MaplePHP","description":"Form builder library","archived":false,"fork":false,"pushed_at":"2023-11-29T15:37:52.000Z","size":115,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-01T21:11:54.392Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MaplePHP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-03-07T15:19:34.000Z","updated_at":"2023-12-22T22:29:59.000Z","dependencies_parsed_at":"2023-11-29T16:19:53.383Z","dependency_job_id":"81f1c925-eccd-4ea3-afee-f88cfc8af1cd","html_url":"https://github.com/MaplePHP/Form","commit_stats":null,"previous_names":["maplephp/form"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FForm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FForm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FForm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MaplePHP%2FForm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MaplePHP","download_url":"https://codeload.github.com/MaplePHP/Form/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245897787,"owners_count":20690457,"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-12-06T14:11:31.780Z","updated_at":"2025-10-24T18:10:11.361Z","avatar_url":"https://github.com/MaplePHP.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MaplePHP - Form builder\nCreate advanced, consistent and secure forms and validations.\n\n## 1. Initiate\n```php\nuse MaplePHP\\Form\\Fields;\nuse MaplePHP\\Form\\Examples\\TestFormFields; // You should create you own template file for fields\n\n$fields = new Fields(new TestFormFields());\n```\n*It is recommended that you make a copy off AbstractFormFields class, make it to a regualar class, rename it and extend it to the real AbstractFormFields abstract class. Then you can start making and adding your own custom input fields.*\n\n### Basic: You can either quick create one field form the fields template\n$fields-\u003e[FIELD_TYPE]-\u003e[ARG1]-\u003e[ARG2]-\u003eget();\n**FIELD_TYPE:** Method name from Form\\Templates\\Fields\n**ARG:** Chainable arguments like input name, fields attributes, validations and so on.\n```php\necho $fields-\u003etext()-\u003ename(\"email\")-\u003elabel(\"Email address\")-\u003eattr([\n        \"type\" =\u003e \"email\", \n        \"placeholder\" =\u003e \"Input your email...\"\n    ])-\u003eget();\n```\n## Advance:\nUse the form compiler for advance consistent form creation and validation. Works really great in frameworks and large applications.\n\n### Create fields\n```\n[\n\tinputFieldName =\u003e [\n\t\t// Field config…\n\t],\n\t…\n\t…\n]\n```\n\n### Field config\n\n#### type (string)\nExpects defined form type key \n**Example:** text, textarea, date, select, checkbox, radio and more.\n*Required*\n\n#### label (string)\nDefine a input label\n**Example:** Email address\n\n#### description (string)\nDefine a input label\n**Example:** We need your email to… \n\n#### attr (array)\nAdd html attributens to field\n**Example:** \n```\n[\n\tclass =\u003e inp-email, \n\ttype =\u003e email,\n\tplaceholder =\u003e Fill in the email\n]\n```\n#### items (array)\nAdd checkbox, radio or select list items.\n**Example:** \n```\n[\n\t1 =\u003e Yes, \n\t0 =\u003e No\n]\n```\n*Is required for field types like select, checkbox and radio.*\n\n#### validate (array)\nAdd validation to form field\n**Example:** \n```\n[\n\tlength =\u003e [1, 200],\n\t!email =\u003e NULL\n]\n```\n*The exclamation point before the email key means that it will **only** validate email if it is filled in else skip or do the other validation.*\n\n#### config (multidimensional array)\nPass on custom data for a custom field.\n**Example:** \n```\n[\n\trole =\u003e admin,\n\tuser_id =\u003e 5212\n]\n```\n## Examples:\n#### 1. Create form with array\nBuild a whole form with array as bellow\n```php\n$fields-\u003eadd([\n    \"firstname\" =\u003e [\n        \"type\" =\u003e \"text\", // Set form type (input text or textarea and so on.)\n        \"label\" =\u003e \"First name\",\n        \"validate\" =\u003e [\n            \"length\" =\u003e [1, 80]\n        ]\n    ],\n    \"lastname\" =\u003e [\n        \"type\" =\u003e \"text\",\n        \"label\" =\u003e \"Last name\",\n        \"validate\" =\u003e [\n            \"length\" =\u003e [1, 120]\n        ]\n    ],\n    \"email\" =\u003e [\n        \"type\" =\u003e \"text\",\n        \"label\" =\u003e \"Email\",\n        \"description\" =\u003e \"We need you email so that we can contact you.\",\n        \"attr\" =\u003e [\n            \"type\" =\u003e \"email\",\n            \"placeholder\" =\u003e \"john.doe@hotmail.com\"\n        ],\n        \"validate\" =\u003e [\n            \"length\" =\u003e [1, 120],\n            \"!email\" =\u003e NULL\n        ]\n    ],\n    \"nested,item1\" =\u003e [\n        \"type\" =\u003e \"radio\",\n        \"label\" =\u003e \"Question 1\",\n        \"validate\" =\u003e [\n            \"length\" =\u003e [1],\n        ],\n        \"items\" =\u003e [\n            1 =\u003e \"Yes\",\n            0 =\u003e \"No\"\n        ],\n        \"value\" =\u003e 1 // Default value\n    ],\n    \"nested,item2\" =\u003e [\n        \"type\" =\u003e \"radio\",\n        \"label\" =\u003e \"Question 2\",\n        \"validate\" =\u003e [\n            \"length\" =\u003e [1],\n        ],\n        \"items\" =\u003e [\n            1 =\u003e \"Yes\",\n            0 =\u003e \"No\"\n        ],\n        \"value\" =\u003e 1 // Default value\n    ],\n    \"message\" =\u003e [\n        \"type\" =\u003e \"textarea\",\n        \"label\" =\u003e \"Message\",\n        \"validate\" =\u003e [\n            \"length\" =\u003e [0, 2000]\n        ]\n    ],\n    \"gdpr\" =\u003e [\n        \"type\" =\u003e \"checkbox\",\n        //\"label\" =\u003e \"GDPR\",\n        \"validate\" =\u003e [\n            \"length\" =\u003e [1, 1],\n            \"!equal\" =\u003e [1]\n        ],\n        \"items\" =\u003e [\n            1 =\u003e \"I accept that my data will be saved according to GDPR\"\n        ]\n    ]\n    \n]);\n```\n#### 2. Set values if you want\nIf you have values from for example the database (accepts multidimensional array and object)\n```php\n$fields-\u003esetValues([\n    \"firstname\" =\u003e \"John\",\n    \"lastname\" =\u003e \"John\",\n    \"nested\" =\u003e [\n        \"item1\" =\u003e 0,\n        \"item2\" =\u003e 1,\n    ]\n]);\n\n```\n#### 3. Build the form\nYou will allways need to build the form before read or validations.\n```php\n$fields-\u003ebuild();\n```\n#### 4. Read form\nNow you can read the form.\n```php\necho '\u003cform action=\"index.php\" method=\"post\"\u003e';\necho $fields-\u003egetForm();\necho \"\u003c/form\u003e\";\n```\n#### 5. Validate form\nNow you can read the form.\n```php\nuse MaplePHP\\Form\\Validate;\n\n$fields-\u003ebuild();\n$validate = new Validate($fields, $_POST);\nif($error = $validate-\u003eexecute()) {\n    // HAS ERROR --\u003e \n\techo \"\u003cpre\u003e\";\n    print_r($error);\n    echo \"\u003c/pre\u003e\";\n\n} else {\n\t// SUCCESS --\u003e\n\t// Return filtered request (will only return values for added input fields)\n\t$request = $validate-\u003egetRequest(); // Uprotected\n}\n\n```\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaplephp%2Fform","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaplephp%2Fform","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaplephp%2Fform/lists"}