{"id":20247856,"url":"https://github.com/formr/extend","last_synced_at":"2025-04-10T22:24:00.784Z","repository":{"id":93876510,"uuid":"297459155","full_name":"formr/extend","owner":"formr","description":"Additional classes to extend Formr","archived":false,"fork":false,"pushed_at":"2023-07-16T16:51:00.000Z","size":17,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T19:21:56.676Z","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":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/formr.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-21T20:55:43.000Z","updated_at":"2024-06-23T19:13:51.000Z","dependencies_parsed_at":"2024-11-14T09:43:48.754Z","dependency_job_id":"68191195-a5c4-4f54-965a-16a952200a05","html_url":"https://github.com/formr/extend","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/formr%2Fextend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formr%2Fextend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formr%2Fextend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formr%2Fextend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/formr","download_url":"https://codeload.github.com/formr/extend/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248307239,"owners_count":21081812,"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-14T09:43:42.295Z","updated_at":"2025-04-10T22:24:00.776Z","avatar_url":"https://github.com/formr.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Extending Formr\n\nThis repo contains classes which will extend Formr by creating your own custom [dropdown menus](https://formr.github.io/methods/#input_select), field wrappers, and [FastForm](https://formr.github.io/fastform/) forms.\n\n## Installation\n\nInstall [Formr](https://github.com/formr/formr) into your project, then download this repo and put the `my_classes` folder into your `Formr` folder. That's it, you're ready to go!\n\nNote that your custom method names have to be unique, so it's a good idea to either prepend your methods with a unique word, such as `\"my\"` e.g.; `myDropdownMenu`, or look inside the appropriate class in `Formr/lib/` to make sure it isn't already used by Formr.\n\n## Creating Custom Dropdowns\n\nAs you know, a `\u003cselect\u003e` menu (dropdown) is nothing more than a series of option tags, consisting of a `value` and a `string` of text contained inside the element.\n\n```html\n\u003clabel\u003eSay Hi!\u003c/label\u003e\n\u003cselect name=\"hello\"\u003e\n  \u003coption value=\"hello_world\"\u003eHello, World!\u003c/option\u003e\n\u003c/select\u003e\n```\n\nThis is really easy to create in Formr, as the select menus are nothing more than simple arrays. Just give your custom method a name, then assign the select menu's `option value` to the `array key`, and the `option string` to the `array value`.\n\n```php\nclass MyDropdowns extends Dropdowns\n{\n  public static function my_hello()\n  {\n    return [\n      'hello_world' =\u003e 'Hello, World!',\n    ];\n  }\n}\n```\n\nAnd then use it like so\n\n```php\n$form-\u003eselect('hello', 'Say Hi!', '', '', '', '', '', 'my_hello');\n```\n\n---\n\n## Creating Custom Forms\n\nYou can create your own forms to be used with [FastForm](https://formr.github.io/fastform/) by creating simple arrays and strings. While it may look complicated, it's actually very easy!\n\n1. The array `key` is the form element type you want to use, e.g.; `text`, `password`, `textarea`, etc.\n2. The array `value` contains the element's parameters.\n\n###### This is how you would normally add an `\u003cinput type=\"text\"\u003e` element in Formr\n\n```php\n$form-\u003etext('name', 'Your name', '', 'nameID', 'placeholder=\"Your name\"');\n```\n\n###### This is how you would build the same `\u003cinput type=\"text\"\u003e` element for FastForm. As you can see, they're basically the same thing!\n\n```php\n'text' =\u003e 'name,Your name,,nameID,placeholder=\"Your name\"'\n```\n\n## Validating Your Custom Forms\n\nValidating your custom forms is just as easy!\n\n1. The array `key` is the form field's `name`.\n2. The array `value` is an array which contains an error message string, and the validation methods.\n\n```php\n'username' =\u003e ['Username|Please enter your username', 'required|min[3]'],\n```\n\n#### Example Login Form\n\nThis is the example login form that comes with the `MyForms` class. Notice how you build your form - and validate it - with simple arrays?\n\n```php\nclass MyForms extends Forms\n{\n  public static function my_login($validate = '')\n  {\n    if (!$validate) {\n      // build the form\n      return [\n        'text' =\u003e 'username,Username,,usernameID',\n        'password' =\u003e 'password,Password,,passwordID',\n        'submit' =\u003e 'submit,,Login',\n      ];\n    } else {\n      // validate the form\n      return [\n        'username' =\u003e [\n          'Username|Please enter your username',\n          'required|min[3]',\n        ],\n        'password' =\u003e ['Password|Please enter your password', 'required|hash'],\n      ];\n    }\n  }\n}\n```\n\nHere's an example of how to use it in your page.\n\n```php\n\u003c!DOCTYPE html\u003e\n\u003chead\u003e\n    \u003ctitle\u003eLogin\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003c?php\n$form = new Formr();\n\nif ($form-\u003esubmitted()) {\n  // validate the $_POST data\n  $post = $form-\u003efastpost('my_login');\n\n  $username = $post['username'];\n  $password = $post['password'];\n}\n\n// print the form\n$form-\u003efastform('my_login');\n?\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n\n```\n\n## Creating Custom Wrappers\n\nCreating custom wrappers in Formr is a bit more complicated and should only be done by someone who is comfortable with HTML and PHP. The basic premise is that there are two methods which work together: the `CSS` method and the `Wrapper` method. The Wrapper method will use CSS classes from the CSS method, so they must go together.\n\nThe best way to get started with Wrappers is to install this package and then take a look at the `simple_wrapper()` method and play around with it.\n\n```php\nclass MyWrappers extends Wrapper\n{\n  public function simple_wrapper($element = '', $data = '')\n  {\n    if (empty($data)) {\n      return false;\n    }\n\n    # open the enclosing \u003cdiv\u003e\n    $return = '\u003cdiv id=\"' . $this-\u003eformr-\u003emake_id($data) . '\" class=\"my-div\"\u003e';\n\n    # let's create a \u003clabel\u003e (if label text was supplied)\n    if ($this-\u003eformr-\u003eis_not_empty($data['label'])) {\n      # open the \u003clabel\u003e\n      $return .=\n        '\u003clabel class=\"my-label\" for=\"' . $this-\u003eformr-\u003emake_id($data) . '\"\u003e';\n\n      # insert the \u003clabel\u003e text\n      $return .= $data['label'];\n\n      # add a required field indicator (*) if present\n      $return .= $this-\u003eformr-\u003einsert_required_indicator($data);\n\n      # close the \u003clabel\u003e\n      $return .= '\u003c/label\u003e';\n    }\n\n    # add the field element, e.g.; \u003cinput type=\"text\"\u003e\n    $return .= $element;\n\n    # close the \u003cdiv\u003e\n    $return .= '\u003c/div\u003e';\n\n    return $return;\n  }\n}\n```\n\n#### Let's try the simple_wrapper()\n\n```php\n$form = new Formr('simple_wrapper');\n$form-\u003etext('name', 'Name');\n\n// outputs the following HTML\n\u003cdiv id=\"name\" class=\"my-div\"\u003e\n    \u003clabel class=\"my-label\" for=\"name\"\u003eName\u003c/label\u003e\n    \u003cinput type=\"text\" name=\"name\" id=\"name\" class=\"form-control\"\u003e\n\u003c/div\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformr%2Fextend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fformr%2Fextend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformr%2Fextend/lists"}