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

ParameterTypeDescription
$namestringThe name attribute for the input element.
$valuestring|null(optional) The email address value.
$attributesarray(optional) HTML attributes for the input element. Defaults to an empty array ([]).

Return Value

TypeDescription
stringAn 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 multiple attribute to allow multiple email addresses separated by commas.
  • Add required attribute for HTML5 client-side validation.
  • Browser validation varies; implement server-side validation with PHP's filter_var($email, FILTER_VALIDATE_EMAIL) or by using the validation module that is included with Trongate.
  • For consistent behavior, always validate email addresses on the server before processing.