form_email()
function form_email(string $name, ?string $value = null, array $attributes = []): string
Description
Generates an HTML email input field with type="email". Provides built-in browser email validation.
Parameters
| Parameter | Type | Description |
|---|---|---|
| $name | string | The name attribute for the input element. |
| $value | string|null | (optional) The email address value. |
| $attributes | array | (optional) HTML attributes for the input element. Defaults to an empty array ([]). |
Return Value
| Type | Description |
|---|---|
| string | An HTML email input element. |
Example #1: Basic Email Input
Example #2: Email Input with Validation Attributes
Most browsers provide basic email format validation, but always validate server-side.
- Use the
multipleattribute to allow multiple email addresses separated by commas. - Add
requiredattribute for HTML5 client-side validation. - Browser validation varies; implement server-side validation with PHP's
filter_var($email, FILTER_VALIDATE_EMAIL)or by using thevalidationmodule that is included with Trongate. - For consistent behavior, always validate email addresses on the server before processing.