2

I am working on a booking system where I have a content type of "Company" with an unlimited Field Collection of "Services". The "Services" field collection has 2 fields: "Service Name" and "Price".

I want users to be able to book any of the Services using an Entityform I have created, so that the Node Title, Service Name and Price fields be loaded automatically on the Entityform during submission.

I have tried using tokens and the Prepolutate module by passing the field values in the URL but I can't seem to pass the values from the Services field collection because field collections are entities on their own, and also this is not very secure as the price can easily be manipulated/changed in the URL.

How should I go about this? Or is there a module that load an Entityform from the URL for example http://www.example.com/company/nid/book, with values of fields and fields collection from the node. Every suggestion will be appreciated.

1

The best way to do this is hook_form_FORM_ID_alter().

Modules can implement hook_form_FORM_ID_alter() to modify elements and values in the form before it is rendered. You'll have to look quite deep into the form array but it should be possible to set the #default_value for the required elements.

1
+50

Entity Form project page says that Entity Form supports Entity reference and Prepopulate Modules.

My suggestion is try with Entity reference autofill and Entityreference prepopulate Modules. Please make a try.

  1. Add an entity reference field in your entityform.
  2. The entity reference autofill will automatically fill reference value into field. We can load default value from URL. (?field_name = value)
  3. Entityreference prepopulate will prepopulate the values. (you have to add existing fields for that.)

For more details please refer project page.

Another approach is,

If you want to do this by coding, Just pass nid through url and use node_load() to load that node and create an entity form submission. If you want to create entity form with node creation use hook_node_insert or hook_node_presave.

Hope this will help you.

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.