Reputation: 1460
I have a Drupal view that displays vacation leaves for a particular employee.
I want to have a button or link right on this view that says 'Add Vacation Leave'. When this button/link is clicked, I want the create content form for Vacation Leave to be displayed with the employee's name already filled in.
When 'Save' is clicked, I would like to go right back to the view, with my new content added. Is all of this possible?
Thanks, Paul
Upvotes: 0
Views: 1189
Reputation: 33275
You can do this without much trouble.
To add the link, you could make a custom template for the view where you add the link. It will be the same for all users, something like, node/node_type/add
. You should make the link with the l()
function, and remember to add the destination to where they should be redirected back to. You should get a url like this: /node/node_type/add&destination=/url/to/current/page
(the / being escaped ofcause).
With destination being set, the default node form, should take care of everything and redirect the user back to the url he came from.
Upvotes: 2
Reputation: 13226
Sure. If I am reading this right, you can write a simple module that implements hook_form_alter, then prefill the form field by doing:
global $user;
$form['name_of_form_field']['#value'] = $user->name;
You can also adjust the redirect within the same function.
There is also a module that can auto populate based on URL variables.
http://drupal.org/project/prepopulate
Upvotes: 1