SO I have two content types, a "Candidate" and a "Job Opening". "Candidate" has an Entity Reference field that points to a Job Opening. I've currently got separate views for both, but on the "Job Opening" view I'd like to have a field that users can click to apply for a job, which would ideally create a new Candidate node with the Job Opening ER field pre-filled so users don't have to fill that in.

I tried adding a Custom Text field containing

<a href="/node/add/candidate">Apply Now!</a>

but I just get an "object not found" error when I click on it.

Is there any way to accomplish this be it with existing modules or built-in stuff, or am I gonna have to dive in and start coding?

Edit: So I've managed to get half of what I want. Turns out because my installation is at "/localhost/drupal", then my link needed to be

<a href="/drupal/node/add/candidate/">Apply Now!</a>

So now I just need to find out how to pass a reference to the job opening its from and I'm golden.

6 Answers 6


It's possible without writing any PHP etc. and you'll need one of the modules mentioned Entityreference prepopulate, Prepopulate, etc.

  1. Add Global: Custom text to your fields, in the Text field enter Apply Now!
  2. Under Rewrite results, check Output this field as a link
  3. In the Link path field enter node/add/candidate (this will get passed through the l() function and correctly deal with subfolders, etc.)
  4. Add Global: Unfiltered text to your header/footer, etc. in the Text field enter [nothing], check Display even if view has no result and check Use replacement tokens from the first row
  5. Test this is working correctly and Exclude from display the Global: Custom text in your fields
  6. Play around with the Link path field to correctly pass the correct variables so your fields are populated correctly - this will probably require trial and error to get this correct which is why this is the last step.
  • are you sure about Link path field will go through l() ? because this will show link to anonymous user too but as mentioned by @texas-bronius l() would take care of unauthorized access. In official [doc] (api.drupal.org/api/drupal/includes%21common.inc/function/l/7.x) there is nothing about authorization or permission/
    – kiranking
    Jan 20, 2017 at 18:03

If you have views php module installed in your drupal installation than you can use $GLOBALS['base_url'] i.e the base_url to get the path of your drupal root and than you can dynamically create the node add link.

One more thing, its better to create the node add link with the l(), as the above example will not work on a site with clean URLs turned off.

  • So you're saying I should grab views php and use the 'l()' function to create the link? What I've done is added a Global:Custom Text field on the view, and entered "<a href="/localhost/drupal/node/add/candidate?field_job_opening=[nid]">Apply Now"</a> as the text. Sep 27, 2013 at 8:38
  • I am advising to you use views_php module to get the base url of the site only, so that you don't need to hard code the base path of the site (which in you case is "localhost/drupal"), and this would be higly beneficial when you move site to live or another server. And using l() is ht best option to create the link as it will automatically take care of clean url. Sep 27, 2013 at 8:48
  • Ah I see. Good idea I'll give that a try. Sep 28, 2013 at 3:28

Requirement is pretty much as Event-Registration scenario.I would recommend you to go through a very nice video video-tutorial by yaworski. Try to get hold of the key logic behind it,you will get job done doing required modifications.


So now I just need to find out how to pass a reference to the job opening its from and I'm golden. -- you can pass node reference from url as well, check out node reference url module

again going with demo videos 1,2 will be worth watching.


I aggree with using l() function to write a link

Then to prepopulate a referenced node/entity, Entityreference prepopulate module can be usefull

Also Node Reference URL Widget module do this

Both have an ID in the url to prepolutate your referenced field when accessing the node/add form

Url looks like : node/add/article/field_parent=112 or node/add/article/112 depends which module your are using

Write your custom link directly in your view with using l() function


Ok, so I'm writing my own answer because I used a bunch of different things from this thread.

First, I decided to use Entityreference Prepopulate since all of the affected fields were already created using the Entity Reference module and I didn't feel like re-making them with Node Reference.

Next, I used views PHP to give me access to the Global: PHP field in Views, and I filled the output code section of the relevant nodes with the following:

<?php print l("Apply Now", $GLOBALS['base_url'] . "/node/add/candidate?field_job_opening=". $row->id); ?>

I used the l() function to ensure that the links are properly formed regardless of Clean URL settings and it should work if/when the sites base url changes.


It's been said a couple times here to add the link using the l(). I'd like to add a complete example to conditionally add a button/link to Add Another Node of whatever content using l() to avoid caring where your site is hosted and to make it so unauthorized users won't see the link. It also adds a destination of the current page in the simplest way possible so that after hitting Save, the user gets taken back to the page (View) wherever the thing is displayed (like in a block throughout the site).

$links = array();
if (user_access('create event content')) {
  $link = l('Add Event', 'node/add/event',
      'query' => drupal_get_destination()
  $links[] = $link;
if (user_access('create performer content')) {
  $link = l('Add Artist', 'node/add/performer',
      'query' => drupal_get_destination()
  $links[] = $link;
if (count($links)) {
  print "<p>" . implode(' | ', $links) . "</p>";

In the example above, I am outputting two links side by side with independent user_access checks, one for each content type.

This snippet would go, for instance, in the Header of a View with the checkbox "Display even if View has no result" checked and Input Type filter set to PHP.

Your Answer

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

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