I designed a student registration form using webforms module. My requirement is to save data from the form to table student. How can i achieve this? Is there anyway to mention this in configuration file?

  • The webform data is already saver om the DB. To save it in a custom table you must implement a hook that updates your custom table when the web form is submitted. – user72672 Sep 13 '19 at 6:21
  • 1
    You can do custom saving of data with Webform Handlers. A tutorial can be found here: stefvanlooveren.me/blog/… – Stef Van Looveren Sep 13 '19 at 6:33

You can add custom submit handler to your Webform through hook_form_alter for inserting it's data into your custom table.

To achieve it check the below example.

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Database\Database;

function MODULE_NAME_form_alter(&$form, $form_state, $form_id){
  if($form['#form_id'] == "YOUR_WEBFORM"){
    $form['actions']['submit']['#submit'][] = 'YOUR_CUSTOM_FUNCTION';

function YOUR_CUSTOM_FUNCTION(&$form, $form_state){
  $query = Database::getConnection();
      'FIELD_NAME_IN_TABLE' => $form_state->getValue('FIELD_NAME_IN_FORM'),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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