{"id":15978949,"url":"https://github.com/phrozenbyte/pico-http-params","last_synced_at":"2025-05-07T06:44:22.306Z","repository":{"id":57041104,"uuid":"68470764","full_name":"PhrozenByte/pico-http-params","owner":"PhrozenByte","description":"This is Pico's official HTTP parameters plugin to access GET and POST parameters in Twig templates.","archived":false,"fork":false,"pushed_at":"2017-11-04T17:46:18.000Z","size":13,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-07T06:44:13.207Z","etag":null,"topics":["html-form","pico","pico-http-params","picocms","picocms-plugin","sanitization","validation"],"latest_commit_sha":null,"homepage":"http://picocms.org/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PhrozenByte.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-17T18:28:44.000Z","updated_at":"2022-10-03T00:51:41.000Z","dependencies_parsed_at":"2022-08-24T01:10:25.217Z","dependency_job_id":null,"html_url":"https://github.com/PhrozenByte/pico-http-params","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhrozenByte%2Fpico-http-params","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhrozenByte%2Fpico-http-params/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhrozenByte%2Fpico-http-params/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhrozenByte%2Fpico-http-params/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PhrozenByte","download_url":"https://codeload.github.com/PhrozenByte/pico-http-params/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252831178,"owners_count":21810779,"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":["html-form","pico","pico-http-params","picocms","picocms-plugin","sanitization","validation"],"created_at":"2024-10-07T23:40:27.339Z","updated_at":"2025-05-07T06:44:22.287Z","avatar_url":"https://github.com/PhrozenByte.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Pico HTTP Parameters\n====================\n\nThis is the repository of Pico's official HTTP parameters plugin.\n\nPico is a stupidly simple, blazing fast, flat file CMS. See http://picocms.org/ for more info.\n\n`PicoHttpParams` allows theme developers to access HTTP GET and HTTP POST parameters in Twig templates using the `url_param` resp. `form_param` functions. This makes developing awesome themes for your Pico website easier than ever before.\n\nThis plugin basically wraps around [PHP's `filter_var()` function](https://secure.php.net/manual/en/function.filter-var.php). Here's a excerpt from PHP's documentation about the [filter extension](https://secure.php.net/manual/en/intro.filter.php):\n\n\u003e This extension filters data by either validating or sanitizing it. This is especially useful when the data source contains unknown (or foreign) data, like user supplied input. For example, this data may come from an HTML form.\n\u003e\n\u003e There are two main types of filtering: validation and sanitization.\n\u003e\n\u003e [Validation](https://php.net/manual/en/filter.filters.validate.php) is used to validate or check if the data meets certain qualifications. For example, passing in `FILTER_VALIDATE_EMAIL` will determine if the data is a valid email address, but will not change the data itself.\n\u003e\n\u003e [Sanitization](https://php.net/manual/en/filter.filters.sanitize.php) will sanitize the data, so it may alter it by removing undesired characters. For example, passing in `FILTER_SANITIZE_EMAIL` will remove characters that are inappropriate for an email address to contain. That said, it does not validate the data.\n\u003e\n\u003e Flags are optionally used with both validation and sanitization to tweak behaviour according to need. For example, passing in `FILTER_FLAG_PATH_REQUIRED` while filtering an URL will require a path (like `/foo` in `http://example.org/foo`) to be present.\n\n\u003csmall\u003e– [Copyright](https://secure.php.net/manual/en/copyright.php) © 1997-2016 [The PHP Documentation Group](https://secure.php.net/credits.php), released under the [Creative Commons Attribution 3.0](https://creativecommons.org/licenses/by/3.0/) license\u003c/small\u003e\n\nInstall\n-------\n\nJust [download the latest release](https://github.com/PhrozenByte/pico-http-params/releases/latest) and upload the `PicoHttpParams.php` file to the `plugins` directory of your Pico installation (e.g. `/var/www/html/pico/plugins/`). The plugin is also available on [Packagist.org](https://packagist.org/packages/phrozenbyte/pico-http-params) and may be included in other projects via `composer require phrozenbyte/pico-http-params`. The plugin requires Pico 1.0+\n\nThis plugin is a backport of an feature that will be included in Pico's core starting with Pico 1.1. Even though this plugin is compatible with Pico 1.1 (and later), it doesn't provide any functionality when used together with Pico 1.1 (and later). Therefore you can safely remove this plugin on Pico 1.1 installations if no other installed plugin depends on it. However, you are not required to. Put briefly, manually installing this plugin makes sense with Pico 1.0 only.\n\nConfig\n------\n\nYou can't configure this plugin, it's a utility plugin for theme developers.\n\nUsage\n-----\n\n**Heads up!** Input validation is hard! Always validate your input data the most paranoid way you can imagine. Always prefer validation filters over sanitization filters; be very careful with sanitization filters, you might create cross-site scripting vulnerabilities!\n\nThe `PicoHttpParams::getUrlParameter()` function resp. the `url_param` Twig function and the `PicoHttpParams::getFormParameter()` function resp. the `form_param` Twig function all accept the following parameters:\n\n| Variable Type | Parameter Name | Description |\n| ------------- | -------------- | ----------- |\n| `mixed` | `$name` | name of the HTTP GET or HTTP POST variable |\n| `int` \\| `string` | `$filter = ''` | ID (int) or name (string) of the filter to apply; if omitted, all functions will return `false` |\n| `mixed` \\| `array` | `$options = null` | either a associative array of options to be used by the filter (e.g. `[ 'default': 42 ]`), or a scalar default value that will be returned when the HTTP GET or HTTP POST variable doesn't exist (optional) |\n| `int` \\| `string` \\| `int[]` \\| `string[]` | `$flags = null` | either a bitwise disjunction of flags or a string with the significant part of a flag constant (the constant name is the result of `FILTER_FLAG_` and the given string in ASCII-only uppercase); you may also pass an array of flags and flag strings (optional) |\n\nWith a validation filter passed in, all functions return the validated value of the HTTP GET or HTTP POST parameter, or, provided that the value wasn't valid, either the given default value or `false`. With a sanitization filter passed in, all functions return the sanitized value of the HTTP GET or HTTP POST parameter. If the HTTP GET or HTTP POST variable doesn't exist, all functions will always return either the provided default value or `null`.\n\nExamples\n--------\n\nPass the boolean HTTP GET parameter `expand` to expand a details section in your template:\n\n```twig\n\u003ca href=\"{{ current_page.id|link('expand=yes') }}\"\u003eLearn more...\u003c/a\u003e\n\n{% if url_param('expand', 'boolean') %}\n    You're learning more right now! Isn't that great!?\n{% endif %}\n```\n\nAsk a user about \"the answer\" using a HTML form and store his decision in the Twig variable `the_answer`. Use a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) to allow just values that are actually present in the HTML form.\n\n```twig\n\u003cform action=\"\" method=\"POST\"\u003e\n    \u003clabel for=\"the_answer\"\u003eWhat is the answer?\u003c/label\u003e\n    \u003cselect id=\"the_answer\" name=\"the_answer\"\u003e\n        \u003coption\u003e\u003c/option\u003e\n        \u003coption value=\"band\"\u003ea Northern Irish hard rock and blues-rock band\u003c/option\u003e\n        \u003coption value=\"42\"\u003e42\u003c/option\u003e\n        \u003coption value=\"what\"\u003eWhat the hell are you talking about?\u003c/option\u003e\n    \u003c/select\u003e\n    \u003cinput type=\"submit\" /\u003e\n\u003c/form\u003e\n\n{% set the_answer = form_param('the_answer', 'validate_regexp', { 'regexp': '/^(band|42|what)$/' }) %}\n```\n\nAsk a user how much he makes a year and claim that his amount is either sad or ridicilous because you make twice as much a year. Use the Twig variable `amount` and let the parameter default to `0`. Use the `FILTER_VALIDATE_FLOAT` (`float`) filter, but tweak its behaviour by passing the `FILTER_FLAG_ALLOW_THOUSAND` flag - this allows the user to enter their amount with a thousand separator (e.g. `12,345.00`).\n\n```twig\n\u003cform action=\"\" method=\"GET\"\u003e\n    \u003clabel for=\"amount\"\u003eHow much do you make a year?\u003c/label\u003e\n    \u003cinput id=\"amount\" name=\"amount\" type=\"text\" /\u003e\n    \u003cinput type=\"submit\" /\u003e\n\u003c/form\u003e\n\n{% set amount = url_param('amount', 'float', 0, 'allow_thousand') %}\n{% if amount \u003e 0 %}\n    {% if amount \u003c 10 %}\n        You make just {{ amount }} cat pictures a year? Oh, that's sad... :-(\n    {% else %}\n        Impressive... Not! This is ridiculous! I make {{ amount * 2 }} cat pictures a year!\n    {% endif %}\n{% endif %}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphrozenbyte%2Fpico-http-params","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphrozenbyte%2Fpico-http-params","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphrozenbyte%2Fpico-http-params/lists"}