I'm in the process of writing a module. The module works very well. In the module, I generate a form which consists of one submit button, and in the .module file, I'm calling that form and the submitForm works too. I was asked to move that button into a block, so I did. submitForm still works, but the main functionality doesn't. How come?
<?php
namespace Drupal\my_module\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Generate button.
*/
class myModuleForm extends FormBase {
/**
* {@inheritdoc}.
*/
public function getFormId() {
return 'my_module_form';
}
/**
* {@inheritdoc}.
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['my_module_btn'] = [
'#type' => 'submit',
'#value' => 'Do something' ];
return $form;
}
/**
* {@inheritdoc}.
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$mpdf = new \Mpdf\Mpdf(['tempDir' => 'sites/default/files/tmp', 'default_font' => 'roboto', 'margin_left' => 6, 'margin_top' => 6, 'margin_right' => 6, 'margin_bottom' => 11]);
...
...
...
$mpdf->Output($title."-".date("Ymd-His").".pdf", 'D');
}
}