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.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI 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.
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.
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';
}
}