Fields
Types
Email

Email Field

An email input field with built-in email format validation.

Basic Usage

$stack->field('contact_email', [
    'type' => 'email',
    'label' => 'Contact Email',
    'default' => '',
    'description' => 'Enter a valid email address',
]);

Properties

PropertyTypeDefaultDescription
typestring-Required. Must be 'email'
labelstring-Field label displayed to users
descriptionstring''Help text below the field
defaultstring''Default value
attributesarray[]Additional HTML attributes
conditionsarray[]Conditional display rules

Attributes

AttributeTypeDefaultDescription
placeholderstring''Placeholder text
readonlyboolfalseMake field read-only
disabledboolfalseDisable the field
multipleboolfalseAllow multiple emails (comma-separated)

Examples

Contact Email

$stack->field('admin_email', [
    'type' => 'email',
    'label' => 'Admin Email',
    'description' => 'Notifications will be sent to this address',
    'attributes' => [
        'placeholder' => 'admin@example.com',
    ],
]);

Support Email

$stack->field('support_email', [
    'type' => 'email',
    'label' => 'Support Email',
    'default' => 'support@example.com',
]);

In a Contact Group

$stack->group('contact', function ($group) {
    $group->field('name', [
        'type' => 'text',
        'label' => 'Contact Name',
    ]);
    
    $group->field('email', [
        'type' => 'email',
        'label' => 'Email Address',
        'attributes' => [
            'placeholder' => 'name@company.com',
        ],
    ]);
    
    $group->field('phone', [
        'type' => 'text',
        'label' => 'Phone Number',
    ]);
}, ['label' => 'Contact Information']);

With Conditional Display

$stack->field('notification_email', [
    'type' => 'email',
    'label' => 'Notification Email',
    'conditions' => [
        ['field' => 'enable_notifications', 'operator' => '==', 'value' => true],
    ],
]);

Retrieving Value

// For options
$email = my_option('contact_email', '');
 
// Validate before use
$email = my_option('contact_email', '');
if (is_email($email)) {
    // Safe to use
}

Output Example

// Contact link
<?php $email = my_option('contact_email', ''); ?>
<?php if ($email): ?>
    <a href="mailto:<?php echo esc_attr($email); ?>">
        <?php echo esc_html($email); ?>
    </a>
<?php endif; ?>

Validation

WordPress provides built-in email validation:

$email = my_option('contact_email', '');
 
if (is_email($email)) {
    wp_mail($email, 'Subject', 'Message');
} else {
    // Invalid email
}

Related Fields

  • text - For general text input
  • url - For URL input