All Projects → auraphp → Aura.Html

auraphp / Aura.Html

Licence: BSD-2-Clause License
Provides HTML escapers and helpers, including form input helpers.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Aura.Html

Aura.input
Tools to describe HTML form fields and values.
Stars: ✭ 60 (+20%)
Mutual labels:  form, aura
ak-vue3
组件库包含了 AutoForm 自动表单、BackTop 返回顶部、Breadcrumb 面包屑、 Button 按钮、Cascader 级联选择器、Checkbox 多选框、Collapse 折叠面板、ColorPicker 颜色选择器、DataPicker 时间选择器、Dialog 弹层对话框、Alert 弹框、Echarts 图形图表、Form 表单、Input 输入框、Lazy 图片延时加载、Loading 加载等待、Menu 菜单、Pagination 分页、Progress 进度条、Radio 单选框、Select 选择器、Steps 步骤条、Swiper 图片轮播、Switch 开关、Table 表格、Tabs 标签页、Textarea 文本框、Tooltip 提示、Tr…
Stars: ✭ 24 (-52%)
Mutual labels:  form
react-form-base
Base React component for generic forms
Stars: ✭ 18 (-64%)
Mutual labels:  form
form
[DEPRECATED] Joomla Framework Form Package
Stars: ✭ 12 (-76%)
Mutual labels:  form
v-form
🎉 基于 Vant-UI 进行二次封装动态生成表单,通过 JSON 的形式配置,内部集成繁琐的校验规则,可扩展的校验
Stars: ✭ 57 (+14%)
Mutual labels:  form
datalize
Parameter, query, form data validation and filtering for NodeJS.
Stars: ✭ 55 (+10%)
Mutual labels:  form
onion-form
React Redux form builder with great UX validations
Stars: ✭ 50 (+0%)
Mutual labels:  form
ModifiedPowerAurasTBC
An advanced wow 2.4.3 power auras
Stars: ✭ 16 (-68%)
Mutual labels:  aura
form-js
View and visually edit JSON-based forms.
Stars: ✭ 125 (+150%)
Mutual labels:  form
GUI
Form Window tools for Nukkit and NukkitX plugin developers
Stars: ✭ 20 (-60%)
Mutual labels:  form
ngx-scroll-to-first-invalid
Directive to scroll to first invalid form control inside an Angular form on submit
Stars: ✭ 27 (-46%)
Mutual labels:  form
node-input-validator
Validation library for node.js
Stars: ✭ 74 (+48%)
Mutual labels:  form
formalizer
React hooks based form validation made for humans.
Stars: ✭ 12 (-76%)
Mutual labels:  form
foect
Simple form validation library for React Native.
Stars: ✭ 39 (-22%)
Mutual labels:  form
Contact-Form-PHP
Simple and secure contact form using Ajax, validations inputs, SMTP protocol and Google reCAPTCHA v3 in PHP.
Stars: ✭ 28 (-44%)
Mutual labels:  form
react-final-form-listeners
A collection of components to listen to 🏁 React Final Form fields
Stars: ✭ 91 (+82%)
Mutual labels:  form
react-native-validator-form
Simple validator for react-native forms.
Stars: ✭ 21 (-58%)
Mutual labels:  form
xForm
基于[email protected]的动态表单生成器。
Stars: ✭ 25 (-50%)
Mutual labels:  form
gravityforms-phone-extension
Extension for GravityForms (WordPress) which applies the International Phone Input (http://intl-tel-input.com) to all Phone Fields.
Stars: ✭ 24 (-52%)
Mutual labels:  form
Fore
Fore - declarative programming with web components
Stars: ✭ 34 (-32%)
Mutual labels:  form

Aura.Html

Provides HTML escapers and helpers, including form input helpers, that can be used in any template, view, or presentation system.

Foreword

Installation

This library requires PHP 5.3 or later with mbstring and/or iconv installed; we recommend using the latest available version of PHP as a matter of principle. It has no userland dependencies.

It is installable and autoloadable via Composer as aura/html.

Alternatively, download a release or clone this repository, then require or include its autoload.php file.

Quality

Scrutinizer Code Quality codecov Continuous Integration

To run the unit tests at the command line, issue composer install and then vendor/bin/phpunit at the package root. This requires Composer to be available as composer.

This library attempts to comply with PSR-1, PSR-2, and PSR-4. If you notice compliance oversights, please send a patch via pull request.

Community

To ask questions, provide feedback, or otherwise communicate with the Aura community, please join our Google Group, follow @auraphp on Twitter, or chat with us on #auraphp on Freenode.

Getting Started

The easiest way to instantiate a HelperLocator with all the available helpers is to use the HelperLocatorFactory:

<?php
$factory = new \Aura\Html\HelperLocatorFactory;
$helper = $factory->newInstance();
?>

Built-In Helpers

Once you have a HelperLocator, you can then use the helpers by calling them as methods on the HelperLocator instance. See the tag helpers and form helpers pages for more information.

N.b.: All built-in helpers escape values appropriately; see the various helper class internals for more information.

Custom Helpers

There are two steps to adding your own custom helpers:

  1. Write a helper class

  2. Set a factory for that class into the HelperLocator under a service name

A helper class needs only to implement the __invoke() method. We suggest extending from AbstractHelper to get access to indenting, escaping, etc., but it's not required.

The following example helper class applies ROT-13 to a string.

<?php
namespace Vendor\Package;

use Aura\Html\Helper\AbstractHelper;

class Obfuscate extends AbstractHelper
{
    public function __invoke($string)
    {
        return $this->escaper->html(str_rot13($input));
    }
}
?>

Now that we have a helper class, we set a factory for it into the HelperLocator under a service name. Therein, we create and return the helper class.

<?php
$helper->set('obfuscate', function () {
    return new \Vendor\Package\Obfuscate;
});
?>

The service name in the HelperLocator doubles as a method name. This means we can call the helper via $this->obfuscate():

<?= $helper->obfuscate('plain text') ?>

Note that we can use any service name for the helper, although it is generally useful to name the service for the helper class, and for a word that can be called as a method.

Please examine the classes in Aura\Html\Helper for more complex and powerful examples.

Escaping

One of the important but menial tasks with PHP-based template systems is that of escaping output properly. Escaping output is absolutely necessary from a security perspective. This package comes with an escape() helper that has four escaping methods:

  • $this->escape()->html('foo') to escape HTML values
  • $this->escape()->attr('foo') to escape unquoted HTML attributes
  • $this->escape()->css('foo') to escape CSS values
  • $this->escape()->js('foo') to escape JavaScript values

Here is a contrived example of the various escape() helper methods:

<head>

    <style>
        body {
            color: <?= $this->escape()->css($theme->color) ?>;
            font-size: <?= $this->escape()->css($theme->font_size) ?>;
        }
    </style>

    <script language="javascript">
        var foo = "<?= $this->escape()->js($js->foo); ?>";
    </script>

</head>

<body>

    <h1><?= $this->escape()->html($blog->title) ?></h1>

    <p class="byline">
        by <?= $this->escape()->html($blog->author) ?>
        on <?= $this->escape()->html($blog->date) ?>
    </p>

    <div id="<?php $this->escape()->attr($blog->div_id) ?>">
        <?= $blog->raw_html ?>
    </div>

</body>

Unfortunately, escaper functionality is verbose, and can make the template code look cluttered. There are two ways to mitigate this.

The first is to assign the escape() helper to a variable, and then invoke it as a callable. Here is a contrived example of the various escaping methods as callables:

<?php
// assign the escaper helper properties to callable variables
$h = $this->escape()->html;
$a = $this->escape()->attr;
$c = $this->escape()->css;
$j = $this->escape()->js;
?>

<head>

    <style>
        body {
            color: <?= $c($theme->color) ?>;
            font-size: <?= $c($theme->font_size) ?>;
        }
    </style>

    <script language="javascript">
        var foo = "<?= $j($js->foo); ?>";
    </script>

</head>

<body>

    <h1><?= $h($blog->title) ?></h1>

    <p class="byline">
        by <?= $h($blog->author) ?>
        on <?= $h($blog->date) ?>
    </p>

    <div id="<?php $a($blog->div_id) ?>">
        <?= $blog->raw_html ?>
    </div>

</body>

Alternatively, the Escaper class used by the escape() helper comes with four static methods to reduce verbosity and clutter: h(), a(), c(), j(), and. These escape values for HTML content values, unquoted HTML attribute values, CSS values, and JavaScript values, respectively.

N.b.: In Aura, we generally avoid static methods. However, we feel the tradeoff of less-cluttered templates can be worth using static methods in this one case.

To call the static Escaper methods in a PHP-based template, use the Escaper as a short alias name, then call the static methods on the alias. (If you did not instantiate a HelperLocatorFactory, you will need to prepare the static escaper methods by calling Escaper::setStatic(new Escaper).)

Here is a contrived example of the various static methods:

<?php use Aura\Html\Escaper as e; ?>

<head>

    <style>
        body {
            color: <?= e::c($theme->color) ?>;
            font-size: <?= e::c($theme->font_size) ?>;
        }
    </style>

    <script language="javascript">
        var foo = "<?= e::j($js->foo); ?>";
    </script>

</head>

<body>

    <h1><?= e::h($blog->title) ?></h1>

    <p class="byline">
        by <?= e::h($blog->author) ?>
        on <?= e::h($blog->date) ?>
    </p>

    <div id="<?php e::a($blog->div_id) ?>">
        <?= $blog->raw_html ?>
    </div>

</body>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].