0

I have two content types: City and Request. Request is entity referenced to city.

Now i created a custom themed node /berlin. On this page i have a button that says "send request", which brings you to the node/add/request form.

The form should now somehow pre-populate the field "field-city" with the previously selected city entity/node.

Additionally the field should be hidden.

Could you guys point me in the right direction?

1

There appears to be a dev version of the Prepopulate module for Drupal 7:

The Prepopulate module allows fields in most forms to be pre-populated from the $_REQUEST variable.

For example, the following URL,

http://www.example.com/node/add/blog?edit[title]=this is the title

will automatically fill the Title field on a new blog post with the words "this is the title". Any field can be prepopulated this way, including taxonomy and CCK fields. You can prepopulate more than one field at a time as well. Prepopulate is excellent for creating bookmarklets. For examples on usage for all of these cases, please read the USAGE.txt file that comes with the module or you can read the online handbook page.

So you would just have to craft that button on your City node page to include the additional variable for your city field.

If for whatever reason this doesn't work exactly to your liking, eg, I am not sure if it allows for hiding of the prepopulated field, it would be fairly trivial to craft the functionality in a form_alter() hook in a custom module.

| improve this answer | |
  • the plugin indeed helps. now i need to figure out how to hide the field... – n00b Mar 16 '14 at 2:55
1

After some more research i came across a module that does exactly what i need! Prepopulating a entity reference field and hiding the form field.

https://drupal.org/project/entityreference_prepopulate

| improve this answer | |
0

The Prepopulate module allows fields in most forms to be pre-populated from the $_REQUEST variable. Maybe you could use that module to fill the city field on the add form.

| improve this answer | |
0

You can try Node Reference URL Widget to auto-populates the field form url and its value can't be change later on. For More information go through the documentation of this module. For Entity reference use Entityreference prepopulate module.

| improve this answer | |
  • this plugin can't handle entity reference. – n00b Mar 16 '14 at 3:12

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.