How can I have a menu item "RSVP" that shows a webform, but after an authenticated user has submitted that webform, clicking on "RSVP" would now bring them back to their submission in edit mode?
rsvpdirect.info:
name = rsvpdirect
description = "Redirects webform nodes to edit if the user has already submitted it once before."
package = Custom
core = 7.x
files[] = rsvpdirect.module
rsvpdirect.module:
<?php
/**
* @file
* Forces redirect of webform node to edit the user's previous submission.
*
*/
/**
* Implementation of hook_node_view()
*/
function rsvpdirect_node_view($node, $view_mode, $langcode) {
global $user;
if ($node->type == 'webform' && $view_mode == 'full' && arg(0) == 'node') {
$submissions = webform_get_submissions(array('nid' => $node->nid, 'uid' => $user->uid));
$submission_count = webform_get_submission_count($node->nid, $user->uid);
if ($submission_count >= 1) {
// Get first submission
$submission = reset($submissions);
drupal_goto('node/' . $node->nid . '/submission/' . $submission->sid . '/edit');
}
}
}