I created a simple custom module where I created a Class Form using a custom template form. If I don't use my custom template (I comment my _theme hook from my .module), when I submit my form, class methods handlers validate and submit are called. But When I use my custom form template, If I submit my form, validate and submit class methods handlers aren't called, I don't understand why.
This is my code; I begin with my templates/form--myformtest-form.html.twig template.
<h1>TEST</h1>
<form{{ element }}></form>
My myformtest.module code is the following.
/**
* Implements hook_theme().
*/
function myformtest_theme($existing, $type, $theme, $path)
{
return array(
'form__myformtest_form' => array(
'render element' => 'form',
'template' => 'form--myformtest-form',
),
);
}
If I comment this hook, my form use the default theme form template. In this case, submit the form call validate and submit class handlers methods. If I don't comment this hook, my form use my custom template. Then when I access to my custom form page and valid the form, validate and submit handler are never called.
This is the simple code from my src/Form/MyformtestForm.php class.
class MyformtestForm extends FormBase {
//...
public function buildForm(array $form, FormStateInterface $form_state) {
$form['textfieldtest'] = [
'#type' => 'textfield',
'#title' => $this->t('textfieldtest'),
'#maxlength' => 64,
'#size' => 64,
];
$form['submit'] = [
'#type' => 'submit',
'#value' => t('Submit'),
];
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
ksm("MyformtestForm Validate handler!");
// logs never displayed when I use my custom template. If I don't use the custom template, this log appears.
}
public function submitForm(array &$form, FormStateInterface $form_state) {
ksm("MyformtestForm Submit handler");
// logs never displayed when I use my custom template. If I don't use the custom template, this log appears.
}
Why handlers aren't called when my form use my custom override? How can I call them?
These are the variables existing from my custom template when I load my form page.