class ClientsideValidationDemoForm in Clientside Validation 8
Same name and namespace in other branches
- 8.2 clientside_validation_demo/src/Form/ClientsideValidationDemoForm.php \Drupal\clientside_validation_demo\Form\ClientsideValidationDemoForm
- 3.0.x clientside_validation_demo/src/Form/ClientsideValidationDemoForm.php \Drupal\clientside_validation_demo\Form\ClientsideValidationDemoForm
- 2.0.x clientside_validation_demo/src/Form/ClientsideValidationDemoForm.php \Drupal\clientside_validation_demo\Form\ClientsideValidationDemoForm
Class ClientsideValidationDemoForm.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\clientside_validation_demo\Form\ClientsideValidationDemoForm
Expanded class hierarchy of ClientsideValidationDemoForm
1 string reference to 'ClientsideValidationDemoForm'
- clientside_validation_demo.routing.yml in clientside_validation_demo/
clientside_validation_demo.routing.yml - clientside_validation_demo/clientside_validation_demo.routing.yml
File
- clientside_validation_demo/
src/ Form/ ClientsideValidationDemoForm.php, line 12
Namespace
Drupal\clientside_validation_demo\FormView source
class ClientsideValidationDemoForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'clientside_validation_demo_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['text_1'] = [
'#type' => 'textfield',
'#title' => $this
->t('Text 1'),
'#description' => $this
->t('Simple required text field.'),
'#required' => TRUE,
];
$form['text_2'] = [
'#type' => 'textfield',
'#title' => $this
->t('Text 2'),
'#description' => $this
->t('Required text field with custom required_error message.'),
'#required' => TRUE,
'#required_error' => $this
->t('This message is coming from #required_error.'),
];
$form['text_3'] = [
'#type' => 'textfield',
'#title' => $this
->t('Text 3'),
'#description' => $this
->t('Required text field with max length.'),
'#required' => FALSE,
'#maxlength' => 10,
];
$form['text_4'] = [
'#type' => 'textfield',
'#title' => $this
->t('Text 4'),
'#description' => $this
->t('Conditionally required text field.'),
'#required_error' => $this
->t('This message is coming from #required_error with #states.'),
'#states' => [
'required' => [
':input[name="text_1"]' => [
'filled' => FALSE,
],
],
],
];
$form['email_1'] = [
'#type' => 'email',
'#title' => $this
->t('E-Mail 1'),
'#description' => $this
->t('Required E-Mail field.'),
'#required' => TRUE,
];
$form['email_2'] = [
'#type' => 'email',
'#title' => $this
->t('E-Mail 2'),
'#description' => $this
->t('E-Mail field.'),
'#required' => FALSE,
];
$form['number_1'] = [
'#type' => 'number',
'#title' => $this
->t('Number 1'),
'#description' => $this
->t('Number field.'),
'#required' => FALSE,
];
$form['number_2'] = [
'#type' => 'number',
'#title' => $this
->t('Number 2'),
'#description' => $this
->t('Number field with max.'),
'#max' => 100,
'#required' => FALSE,
];
$form['number_3'] = [
'#type' => 'number',
'#title' => $this
->t('Number 3'),
'#description' => $this
->t('Number field with min.'),
'#min' => 100,
'#required' => FALSE,
];
$form['number_4'] = [
'#type' => 'number',
'#title' => $this
->t('Number 4'),
'#description' => $this
->t('Number field with min and max.'),
'#min' => 100,
'#max' => 200,
'#required' => FALSE,
];
$form['number_5'] = [
'#type' => 'number',
'#title' => $this
->t('Number 5'),
'#description' => $this
->t('Number field with min, max and step.'),
'#min' => 100,
'#max' => 200,
'#step' => 5,
'#required' => FALSE,
];
$form['url'] = [
'#type' => 'url',
'#title' => $this
->t('URL'),
'#description' => $this
->t('URL field.'),
'#required' => FALSE,
];
$form['phone_1'] = [
'#type' => 'textfield',
'#title' => t('Phone Number'),
'#size' => 60,
'#maxlength' => 14,
'#pattern' => "[789][0-9]{9}",
'#required' => TRUE,
'#placeholder' => t('Enter Phone Number - [789][0-9]{9}'),
];
$form['text_equal_1'] = [
'#type' => 'textfield',
'#title' => $this
->t('Equal To'),
'#description' => $this
->t('Field equal to another field.'),
'#required' => TRUE,
];
$form['text_equal_2'] = [
'#type' => 'textfield',
'#title' => $this
->t('Equal to check - default message'),
'#description' => $this
->t('Field equal to another field.'),
'#equal_to' => 'text_equal_1',
'#required' => TRUE,
];
$form['text_equal_3'] = [
'#type' => 'textfield',
'#title' => $this
->t('Equal to check - custom message'),
'#description' => $this
->t('Field equal to another field.'),
'#equal_to' => 'text_equal_1',
'#required' => TRUE,
'#equal_to_error' => $this
->t('Text should match value in Equal To.'),
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
$form['submit_ajax'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit AJAX'),
'#ajax' => [
'callback' => '::submitAjax',
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->messenger()
->addStatus($this
->t('All form validations passed.'));
}
/**
* Ajax submit callback.
*/
public function setMessage(array $form, FormStateInterface $form_state) {
$response = new AjaxResponse();
return $response;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClientsideValidationDemoForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
ClientsideValidationDemoForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ClientsideValidationDemoForm:: |
public | function | Ajax submit callback. | |
ClientsideValidationDemoForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
ClientsideValidationDemoForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
87 |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |