1

I want to save webform submissions in node table..

I want to use the solution from "How to create a node out of a webform submission?".

How can I implement it? I used hook_form_alter but it doesn't work.

2

The question about "How to create a node out of a webform submission?" that you linked to, is about D8, while yours is about D7 ...

In D7, for sure,, you can use the Rules module for this. As an example, consider this rule (in Rules export format), which does what you're asking for:

{ "rules_create_a_node_from_webform_data" : {
    "LABEL" : "Create a node from webform data",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "webform_rules", "rules" ],
    "ON" : { "webform_rules_submit" : [] },
    "IF" : [
      { "webform_has_id" : {
          "form_id" : [ "form_id" ],
          "selected_webform" : { "value" : { "webform-client-form-191" : "webform-client-form-191" } }
        }
      }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "The webform submitted contains these fields:\r\n\u003C\/ul\u003E\r\n\u003Cli\u003Ethe field labeled \u0022[data:demoform_title-title]\u0022 which has value \u0022[data:demoform_title-value-raw]\u0022.\u003C\/li\u003E\r\n\u003Cli\u003E the field labeled \u0022[data:demoform_text-title]\u0022 which has value \u0022[data:demoform_text-value-raw]\u0022.\u003C\/li\u003E\r\n\u003Cli\u003E the field labeled \u0022[data:demoform_number-title]\u0022 which has value \u0022[data:demoform_number-value-raw]\u0022.\u003C\/li\u003E\r\n\u003Cli\u003E the field labeled \u0022[data:demoform_option-title]\u0022 which has value \u0022[data:demoform_option-value-raw]\u0022.\u003C\/li\u003E\r\n\u003C\/ul\u003E" } },
      { "variable_add" : {
          "USING" : { "type" : "text", "value" : "[data:demoform_text-value-raw]" },
          "PROVIDE" : { "variable_added" : { "var_demoform_text" : "Form variable text" } }
        }
      },
      { "variable_add" : {
          "USING" : { "type" : "text", "value" : "[data:demoform_number-value-raw]" },
          "PROVIDE" : { "variable_added" : { "var_demoform_number_text" : "Form variable number text" } }
        }
      },
      { "data_convert" : {
          "USING" : { "type" : "integer", "value" : [ "var-demoform-number-text" ] },
          "PROVIDE" : { "conversion_result" : { "var_demoformvar_number" : "Form variable number" } }
        }
      },
      { "variable_add" : {
          "USING" : { "type" : "text", "value" : "[data:demoform_option-value-raw]" },
          "PROVIDE" : { "variable_added" : { "var_demoform_option" : " Form variable option" } }
        }
      },
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "article",
            "param_title" : "[data:demoform_title-value-raw]",
            "param_author" : [ "user" ]
          },
          "PROVIDE" : { "entity_created" : { "article_created" : "Created article" } }
        }
      },
      { "data_set" : {
          "data" : [ "article-created:body:value" ],
          "value" : [ "var-demoform-text" ]
        }
      },
      { "data_set" : {
          "data" : [ "article-created:field-free-format-nr" ],
          "value" : [ "var-demoformvar-number" ]
        }
      },
      { "data_set" : {
          "data" : [ "article-created:field-optionlist" ],
          "value" : [ "var-demoform-option" ]
        }
      },
      { "data_set" : { "data" : [ "article-created:comment" ], "value" : "0" } },
      { "entity_save" : { "data" : [ "article-created" ], "immediate" : "1" } },
      { "drupal_message" : { "message" : "A new article got created, with nid=[article-created:nid] and url=[article-created:url]" } }
    ]
  }
}

Anybody a bit familiar with Rules and Webform, while know that it's often a struggle to get access to the data contained in a submitted Webform. Mostly because they are not available to select them when building Rules Actions.

However by introducing those var-demoform-... variables (as in the above rule), you can make the typical Rules magic happen. Refer to my answer to "How to create a node from a Webform using rules?" for more details about all this.

  • @A.Sana Thanks for your accept / +1 ..."that's great too!". Next question? – Pierre.Vriens Mar 26 '18 at 11:30
  • my webform contains many components like address, phone number.. I need to save this data in fields table.. How can I do that? Thank you – A.Sana Mar 26 '18 at 12:27
  • @A.Sana How is the question in your last comment different from your original question here? Maybe you should post a new question about that? – Pierre.Vriens Mar 26 '18 at 13:35
  • If I do not seperate any role, normally all users can fill the webform.. is not it? even anonymous? in my case the event created in rules only fires if the admin that fills the webform – A.Sana Mar 28 '18 at 8:39
  • In my admin/reports/dblog, I have this message "Unable to get variable article_created, it is not defined." – A.Sana Mar 28 '18 at 9:21
1

Try hook_form_alter into your custom module file.

/*
* Implement hook_form_alter()
*/
function mymodule_form_alter( &$form, &$form_state,$form_id ){
  // this is for your developer information and shows you the
  // structure of the form array
  dpm($form);
  // this will give you the details for my_form_component
  $a_component = $form['submitted']['my_form_component'];
  dpm($a_component);

  // you'll want to limit your altering to specific forms
  if ($form_id == 'my_webform_client_form_id') {
    // edit component values like this:
    $form['submitted']['my_form_component']['#title'] = 'A spurious text title';
    $from['#submit'] = 'custom_form_submit';
  }
}

https://www.drupal.org/node/1558246

  • Thanks for your answer! That doesn't work for me! I used @Pierre.Vriens 's solution – A.Sana Mar 27 '18 at 9:30

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.