Skip to content

Latest commit

 

History

History
86 lines (67 loc) · 3.78 KB

email.md

File metadata and controls

86 lines (67 loc) · 3.78 KB

Email widget

Email is an input element for editing a list of e-mails.

Usage

<?php

declare(strict_types=1);

namespace App\Form;

use Yii\Extension\Model\FormModel;

final class TestForm extends FormModel
{
    public string $email = '';
}

Widget view:

<?php

declare(strict_types=1);

use Yii\Extension\Form\Email;
use Yii\Extension\Form\Form;
use Yii\Extension\Form\SubmitButton;
use Yii\Extension\Model\Contract\FormModelContract;

/**
 * @var FormModelContract $data
 * @var object $csrf
 */
?>

<?= Form::widget()->action('widgets')->csrf($csrf)->begin() ?>
    <?= Email::widget()->for($data, 'email') ?>
    <hr class="mt-3">
    <?= Field::widget()->class('button is-block is-info is-fullwidth')->submitButton()->value('Save') ?>
<?= Form::end() ?>

That would generate the following code:

<form action="widgets" method="POST" _csrf="aqOSIrAAlb-ZZI-M8OWYQd8hkpCTXEYVqQpAz4y3o-YazP4Ug1PD6d8L3PrAgPoTrFPR-9sDKkPjQCGYyNrojA==">
    <input type="hidden" name="_csrf" value="aqOSIrAAlb-ZZI-M8OWYQd8hkpCTXEYVqQpAz4y3o-YazP4Ug1PD6d8L3PrAgPoTrFPR-9sDKkPjQCGYyNrojA==">
    <input type="email" id="testform-email" name="TestForm[email]">
    <hr class="mt-3">
    <div>
        <input type="submit" id="submit-30061675597001" class="button is-block is-info is-fullwidth" name="submit-30061675597001" value="Save">
    </div>
</form>

Email methods:

Method Description Default
maxlength(int $length) Set the maximum length of the input ''
minlength(int $length) Set the minimum length of the input ''
multiple(bool $value = true) Specifies that the element allows multiple values ''
pattern(string $value) Specifies a regular expression for validate the input ''
placeholder(string $value) Set the placeholder of the input ''
size(int $size) The height with multiple is true ''

Common methods:

Method Description Default
autofocus(bool $value = true) Set the autofocus attribute false
attributes(array $attributes = []) The HTML attributes for the widget []
class(string $class) The CSS class for the widget ''
charset(string $value) Set the charset attribute UTF-8
disabled(bool $value = true) Set the disabled attribute false
encode(bool $value) Whether content should be HTML-encoded true
for(FormModelContract $formModel, string $attribute) Configure the widget
id(string $value) Set the id attribute ''
name(string $value) Set the name attribute. ''
tabIndex(int $value) Set the tabindex attribute ''
title(string $value) Set the title attribute ''
value(string $value) Set the value attribute ''