I have a site that list different courses that take place in real life (not virtual courses). For each course, there are different fields :

  • title of the course
  • start date
  • end date
  • place where the course will happen
  • type of course
  • ...

With View I have created a table that list all the courses. I would like that logged users can subscribe to a course by just clicking on it, and then I would receive an e-mail (or see in the back-end) that tells me that user X has subscribe to course Y (and I will have in the same time all the informations about the course the user subscribed to : title, dates, place...)

For the moment when a logged user click on a course, another page loads that displays informations about the course, and a form where the user have to write out again all the informations in blank fields...

Is there a way to pre-fill the form fields with the informations of the course ?

Or is there a smarter way to do this ?


2 Answers 2


You could use Prepopulate module to prefill fields in subscriptions. But:

I would redesign the model in order not to save the same information you already have in courses again with the subscription. It's redundant to store title, date, place, etc. twice, with all the implications changes of the primary information in courses would have.

Said this content type "subscription" only should save a entity reference to courses. I propose to add a link to each course in Views which allows to subscribe to it. To do this, follow this steps:

  1. Add field "ID" and check "Exclude from display".
  2. Add "Global: Custom text" to your fields and put a label like Subscribe.
  3. Under Rewrite results, check "Output this field as a custom link".
  4. In field "Link path" enter node/add/subscription?edit[course]={{nid}} - where "course" is the name of entity reference field in content type subscription and "nid" is the replacement pattern for the course id.
  5. Install and activate Prepopulute module

Clicking a subscription link in Views should now open subscription form and prefill the referenced course field. Making a custom module would allow you to create this content type without showing the form to the user.

  • Thx for your answer. This solution seems to be great but the one from @4k4 with the "node cache tag" is faster I think. I will check both.
    – Xoclaf
    Commented Feb 12, 2017 at 16:15

You set a '#default_value' in the form field. But this only makes sense, if the user is allowed to change the course data. If not you could add the displayed course data after submit to the confirmation e-mail. Add the node cache tag to the form, so that it gets updated when the node is modified.

A way to approach this

is to set up a form route /subscription/add/{nid} to use as a link in the view, where nid is the node id of the course.

The form loads this node from the route and displays the course data in the form as markup together with the form fields for the user to fill in the personal information. After submit you send a confirmation mail with the personal information and the course data, which you can load again if you keep the node id in a hidden field.

This is the cache tag you have to add to the form, when the form contains data from this node:

$form['#cache']['tags'][] = 'node:' . $node->id();
  • Thx for your answer. The user can not change the course data. So the solution with the "node cache tag" seems great, but how do I do that ?
    – Xoclaf
    Commented Feb 12, 2017 at 16:10
  • For a possible solution see edited answer.
    – 4uk4
    Commented Feb 12, 2017 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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