SimpleRecaptchaTestForm.php in Simple Google reCAPTCHA 8
File
tests/modules/simple_recaptcha_test/src/Form/SimpleRecaptchaTestForm.php
View source
<?php
namespace Drupal\simple_recaptcha_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class SimpleRecaptchaTestForm extends FormBase {
public function getFormId() {
return 'simple_recaptcha_test';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['recaptcha_test_name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Name'),
'#required' => TRUE,
];
$form['recaptcha_test_file'] = [
'#type' => 'managed_file',
'#title' => $this
->t('Example file'),
'#required' => FALSE,
'#upload_location' => 'public://',
'#multiple' => FALSE,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Form submit'),
'#attributes' => [
'id' => 'simple-recaptcha-submit-button',
],
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->messenger()
->addStatus('Clicked on ' . $form_state
->getTriggeringElement()['#id']);
}
}