22 votes
Accepted

Webform File Upload field

You need to enable webform UI, then set in your sites/default/settings.php file the privates files directory path: $settings['file_private_path'] = 'sites/default/files/private'; where 'sites/default/...
Stéphane Gouré Bi's user avatar
16 votes

How to prevent an Ajax form from submitting

I found the solution here. // Add submit handler to form.beforeSend. // Update Drupal.Ajax.prototype.beforeSend only once. if (typeof Drupal.Ajax !== 'undefined' && typeof Drupal.Ajax....
jrockowitz's user avatar
  • 4,623
15 votes
Accepted

How to show webform as block

Special thanks to Peacog Web Development for their great tutorial .Here is the tip: Rather than Drupal 7, Different Block types can be created by admin so the solution is simple : Create a new ...
Alireza Tabatabaeian's user avatar
14 votes
Accepted

Programmatically Render a Webform

I managed to find a method for the webform entity class called getSubmissionForm. I found it in the webform module code in src/Entity/Webform.php I invoked it like so $webform = \Drupal::...
Amy's user avatar
  • 5,662
14 votes
Accepted

Display webform in a modal

Displaying a weform in modal (might be called popup as well) it is a lot simpler than you thought Lets assume your webform has URL /contact than you can create a link in the following manner <a ...
GiorgosK's user avatar
  • 8,443
12 votes

Programmatically Render a Webform

You can also just return a render array. [ '#type' => 'webform', '#webform' => 'my_webform', '#default_data' => [ 'nid' => 10 ] ]
Marek Vantuch's user avatar
12 votes
Accepted

Programmatically update Webform Submission by sid

Try using \Drupal\webform\WebformSubmissionInterface::getData(); and \Drupal\webform\WebformSubmissionInterface::setData($data); // Load submission using sid. /** @var \Drupal\webform\...
jrockowitz's user avatar
  • 4,623
12 votes
Accepted

Load webform submission

I think you have to load sid like below // Load submission using sid. /** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */ $webform_submission = \Drupal\webform\Entity\...
sivani's user avatar
  • 304
12 votes

Webform 'add element' and 'addpage' buttons do not appear

You need to go to admin/config/development/performance and clear the cache. Add element and add page will appear.
Stanley Fernandes's user avatar
11 votes
Accepted

Query webform submissions

Webform submissions are content entities, so something like this should work: $query = \Drupal::entityQuery('webform_submission') ->condition('uid', $uid) ->accessCheck(FALSE); $result = ...
Clive's user avatar
  • 167k
11 votes

How to show webform as block

logeshvaran is correct: Webform for Drupal 8 already provides a block that can reference a webform. So no need to create a custom block type.
eigentor's user avatar
  • 311
10 votes
Accepted

Is there a "best practice" for overriding a contributed module's controller?

To avoid conflicts with other modules you could alter the controller content in a kernel VIEW event similar to a form alter hook: src/EventSubscriber/ControllerAlterSubscriber.php: <?php namespace ...
4uk4's user avatar
  • 99.2k
9 votes

Programmatic list of Webform elements?

By trawling through the code, I found this handy function in the Entity code, and it works perfectly: $elements = $webform->getElementsDecodedAndFlattened(); This gives a nice array of the ...
Michael D. Moradzadeh's user avatar
8 votes

Programmatically Render a Webform

Matt answers works for me but if you want to have a more complete theme structure with it, you would better use : $webform = \Drupal::entityTypeManager()->getStorage('webform')->load('...
Pauleau's user avatar
  • 511
8 votes

How to create a node out of a webform submission?

Also, check out the Webform Content Creator module. This module provides the ability to create nodes after submitting webforms, and do mappings between the fields of the created node and ...
jrockowitz's user avatar
  • 4,623
8 votes
Accepted

Programmatically get webform submissions of a specific nodes webform

Thank you 4k4. Here is now the correct and full code for use in mytheme.theme file (we need the getData() function: $storage = \Drupal::entityTypeManager()->getStorage('webform_submission'); $...
drupalfan's user avatar
  • 650
8 votes
Accepted

Page redirect in custom WebformHandlerBase

Example for a webform handler plugin redirecting: <?php namespace Drupal\sa_webform\Plugin\WebformHandler; use Drupal\Core\Form\FormStateInterface; use Drupal\webform\Plugin\WebformHandlerBase; ...
rdev's user avatar
  • 101
8 votes

How to show webform as block

From Drupal 8 admin Create your webform Structure => Block Layout => click "Place Block" under your preferred region Find Webform then => Place Block => under Webform type your webform title and it ...
hzak's user avatar
  • 337
7 votes
Accepted

Webform response: "Illegal information. Data not submitted."

It seems that message is triggered by the _webform_submission_spam_check function. Looking at the code, it seems to check the following regular expression: '/(b?cc\s?:)|(content\-type:)/i', $to . "\n"...
dinopmi's user avatar
  • 2,587
7 votes
Accepted

How to change webform default email address from sender side?

You can usually find a configure link in the module list. Looks like in /admin/config/content/webform and scroll down to default e-mail values. (For Drupal 6, go to yoursite.com/admin/settings/...
No Sssweat's user avatar
  • 31.1k
7 votes

How do I modify a webform submission field right before it is saved?

You can use preSave method in your handler. Please check out the Webform module handler tests module which is part of Webform codebase, it has TestWebformHandler.php file which defines the submission ...
kenorb's user avatar
  • 14.2k
7 votes
Accepted

How do I alter webform values before submission?

The answer linked is mostly right, just a couple of updates to get it working. In a custom .module add: use Drupal\Core\Form\FormStateInterface; function MODULENAME_form_alter(&$form,$form_state,...
HeyOkaySaturday's user avatar
7 votes

How to create a node out of a webform submission?

The answer from @owenpm3 is great for adding this as an administrative duty. In order to automate this and make it occur on a successful submission, I would create a custom WebformHandler that you ...
Andrew Wasson's user avatar
7 votes
Accepted

How to display title of a webform in twig template Drupal 8

Here is what I came up with function THEMENAME_preprocess_webform(&$vars){ $wfid = $vars["element"]["#webform_id"]; $wf = \Drupal\webform\Entity\Webform::load($wfid); $vars["title"] = $wf-&...
GiorgosK's user avatar
  • 8,443
6 votes

How to add html to the form?

No need to declare a form element as #type = 'markup', as this is the default type. $html = '<strong>My HTML</strong>'; $form['mymarkup'] = array( '#markup' => $html, ); Refer to: ...
Ivan  Azarkevich's user avatar
6 votes
Accepted

How to access webform elements in webform.html.twig

I have figured out a solutions for this situation. create a tempalte file for your form (ex. webform--newsletter.html.twig) there is a variable (element) where you can access each field of the form ...
Ibrahim Samir's user avatar
6 votes
Accepted

Drupal 8 Webform - Pass submitted value from one webforms to another

Ok I figured it out - for anyone else who comes across this question. In the first Webform, I set the Confirmation URL to: /form/my-form2?value=[webform_submission:values:element_key] I've bolded ...
FrankDesign's user avatar
6 votes

How do I create custom webform element?

There are many example module in the webform module itself, and three examples of custom elements all quite clear and detailed: Composite element - webform/modules/webform_example_composite Element - ...
Duncanmoo's user avatar
  • 2,931
6 votes
Accepted

Unable to programmatically render webform with supplied default values

Did you try using the Webform render element documented at the bottom of https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-embed-a-webform. return [ '#type' => 'webform', '#...
jrockowitz's user avatar
  • 4,623
6 votes
Accepted

Webform multi-page submit handler fires on every page

You can use $webform_submission->getState() to determine if the submission is completed. The EmailWebformHandler includes decent examples on how to the submission state. I recommend trying to use ...
jrockowitz's user avatar
  • 4,623

Only top scored, non community-wiki answers of a minimum length are eligible