0

We are using Drupal 8 and trying to solve this problem: A form shall be presented to website visitors that asks them to submit questions (in our case: concerning nutrition) and give some structured background information like the region the user comes from etc.

The submitted information shall then be transformed into a node of a given content type to make it easier for the editorial staff to edit that question in the backend, add an answer to it and publish the whole thing.

The forms shall be used by anonymous users and we do not want to let them create nodes directly via /node/add - for security reasons on one hand and with regard to the complexity of the creation form which is not needed at that point on the other hand.

I have read this: How to create a node with submissions of a webform? but I am not sure whether that would be a solution to our task. It says: "Hide the toolbar for other users and give them permission to add new content. Lastly, adapt the node form to your needs with a template file and style it with CSS." Would I have to expose parts of the backend to anonymous users and give them the right to create new nodes? We would like to avoid that due to security concerns.

  • 1
    Possible duplicate of How to create a node with submissions of a webform? – leymannx Jun 29 '18 at 10:50
  • Hey hey, welcome to Drupal Answers. Why exactly did the linked answer not solve your problem. Please update your question to help us to differ both questions :) – leymannx Jun 29 '18 at 10:51
  • You also may have a look at drupal.stackexchange.com/questions/229651/… – leymannx Jun 29 '18 at 10:53
  • Better use content moderation states and customized form display modes instead of webforms. You certainly will have a better security base when using core techniques than using some weird hacks. – Hudri Jun 29 '18 at 10:57
  • @leymannx: Thanks! I've updated the question with my concerns regarding the linked answer. – LousyWeather Jun 29 '18 at 15:09
-1

I did this previously on Drupal 7 and it might be possible to adapt the process I used:

Via hook_form_alter add an additional submission handler (i.e. form['#submit'][] = '_webform_submit_handler';)

Inside the submission handler function:

  1. Create a new node (i.e. $node = new stdClass();)
  2. Assign the relevant fields (i.e. $node->title = 'Title';, $node->type = "type";, etc.)
  3. Save the node (i.e. $node = node_submit($node); and node_save($node);)

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.