0

I have webform created via Webform UI, and it's multi-step webform.

In second step ('personal information') I add custom button using HOOK_form_alter with following code

'generate_pdf' => [
    '#type' => 'submit',
    '#value' => t('Generate PDF'),
    '#limit_validation_errors' => [],
    '#submit' => ['generate_pdf_template'],
]

function generate_pdf_template takes values from $form, $form_state inserts them into twig templat, creates PDF and automatically downloads it.

My issue is, that this generate_pdf button submits the form and user is not able to send form via original submit button. Can I somehow prevent submission when generate_pdf is clicked so user can download PDF and still be able to send webform with original button and webform's handlers.

1 Answer 1

1

Something like this may work.

#name and #submit are required.

The name makes sure the button does not get confused with other submit buttons.

The #submit value calls a custom function you have to create.

#limit_validation_errors prevents form validation, which may or may not be useful.

  $form['generate_pdf'] = [
    '#type' => 'submit',
    '#value' => $this->t('Generate PDF'),
    '#name' => 'generatepdf',
    '#submit' => ['::generatepdf'],
    '#limit_validation_errors' => array(),
  ];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.