Skip to content

InputBuilder API

The InputBuilder is a specialized builder for creating input dialogs. It provides methods for configuring all SweetAlert2 input types, validation, placeholders, and server-side pre-confirm callbacks.

Import

php
use RealRashid\SweetAlert\Builders\InputBuilder;

Creation

Input dialogs are typically created via the Alert facade:

php
use RealRashid\SweetAlert\Enums\InputType;

Alert::input('Enter your email', InputType::Email)
    ->inputPlaceholder('user@example.com')
    ->flash();

Default Configuration

SettingDefaultWhy
showConfirmButtontrueUsers need to submit their input
showCancelButtontrueUsers need to cancel
confirmButtonText'Submit'Action-oriented label
cancelButtonText'Cancel'Standard cancel label
showCloseButtonfalseClose button is redundant with cancel
allowOutsideClickfalsePrevent accidental dismissal
customClass[]No custom classes by default

Factory Methods

MethodReturnDescription
make()staticCreate a new builder from the container
reset()staticReset to default configuration

Core Configuration

MethodParametersDescription
title(string $title)Dialog titleSet the heading text
text(string $text)Description textSet body text below the title
icon(string|AlertType $type)Icon typeSet the dialog icon

Input-Specific Methods

MethodParametersDescription
inputType(string|InputType $type)Input typeSet the input type (text, email, select, etc.)
inputPlaceholder(string $text)Placeholder textSet input placeholder
inputValue(string $value)Default valuePre-fill the input
inputOptions(array $options)Options arraySet options for select/radio inputs
inputAttributes(array $attributes)HTML attributesSet input HTML attributes
inputValidator(string $message)Error messageSet client-side validation message
inputLabel(string $label)Label textSet input label
inputAutoFocus(bool $enabled = true)Enable/disableAuto-focus the input
inputAutoTrim(bool $enabled = true)Enable/disableAuto-trim whitespace
preConfirmRoute(string $route)Route URLSet server-side validation route
inputClass(string $class)CSS classSet input CSS class

Flash & Serialize

MethodReturnDescription
flash(string $type = 'config')staticFlash to session
toArray()arrayGet filtered config
toJson()stringGet config as JSON
getConfig()arrayGet raw config array

Inherited Traits

InputBuilder uses the same traits as AlertBuilder and inherits all their methods:

  • HasTimer: timer(), autoClose(), timerProgressBar(), persistent()
  • HasPosition: position(), top(), topStart(), topEnd(), center(), centerStart(), centerEnd(), bottom(), bottomStart(), bottomEnd()
  • HasButtons: showConfirmButton(), confirmButton(), showCancelButton(), cancelButton(), showDenyButton(), denyButton(), showCloseButton(), hideCloseButton(), reverseButtons(), buttonsStyling(), focusConfirm(), focusCancel(), showLoaderOnConfirm()
  • HasAnimation: animation(), disableAnimation(), showClass(), hideClass()
  • HasStyling: width(), padding(), background(), color(), heightAuto(), customClass(), iconHtml(), iconColor(), imageUrl(), addImage(), footer(), grow(), backdrop(), allowEscapeKey(), allowOutsideClick(), stopPropagation()

See the AlertBuilder API for full method details on inherited traits.

Made with ❤️ from Pakistan Released under the MIT License.