2

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');
    }
  }
}

1 Answer 1

1

You can do it using hook_node_view and redirect functionality to redirect if webform is submitted. Your menu link always point to webform page.

function YOURMODULENAME_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');
    }
  }
}
5
  • I've installed the module with source code (included now in my question) and when I visit domain.com/rsvp1 (the name of my webform) it gives me a page that has an error box indicating: You have already submitted this form.
    – Bryden
    Commented Feb 28, 2014 at 1:28
  • Post your .module code here to investigate...
    – Anil Sagar
    Commented Feb 28, 2014 at 1:38
  • it's in my original question now.. I don't know how to post code in this comment section. Look up ^
    – Bryden
    Commented Feb 28, 2014 at 1:50
  • Can you clear cache and try ? Which version of Drupal are you using ?
    – Anil Sagar
    Commented Feb 28, 2014 at 1:52
  • v7.26. I just noticed rsvpdirect enable checkbox for the module won't stay enabled. I must have made a typo somewhere..
    – Bryden
    Commented Feb 28, 2014 at 1:56

Your Answer

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

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