Is there a way to change the submitted date and username of a webform result? I have set up a sales deal webform and have information on old deals from sales reps. I'd like to add that information as webform results by the original date and username.

Comments

quicksketch’s picture

Title: Change date submitted? » Change submission date and user
Category: support » feature

This currently isn't possible, other than manually updating the values in the database. Let's move it to a feature request.

miro_dietiker’s picture

We're working on this.

alawneh86’s picture

Assigned: Unassigned » alawneh86
StatusFileSize
new2.98 KB

The patch attached give permission to change the submission author and date.

quicksketch’s picture

Thanks, this looks pretty good. A few needed changes:

- Format the form so that each element is a defined array like this:

$form['admin'] = array(
  '#property' = 'x',
  '#property' = 'y',
);

- Use $form_state['values'] instead of $form['#post']. $_POST is spoofable, $form_state is double-checked by Drupal.

quicksketch’s picture

Status: Active » Needs work
miro_dietiker’s picture

:-) that's what i was just right before submitting: form_state values and permission checks...
quicksketch: when using the ['values'] there's no further permission check needed in the submit function?

quicksketch’s picture

$form_state['values'] is impossible to spoof from the client-side, so you shouldn't need additional checks. Note that hidden fields are NOT enforced at a particular value, unless you use #value instead of #default_value.

alawneh86’s picture

StatusFileSize
new3.19 KB

This is a new patch according the latest changes on the module.
I used array format inside the form alter,
also i used $form_state['values'] rather $form['#post'].

miro_dietiker’s picture

Here we go some review about current state.

+++ webform.module	2 Jun 2010 13:40:44 -0000
@@ -1063,6 +1064,47 @@
+  if (user_access('change submission author')) {

Is there no further global webform admin permission to check and pass?

+++ webform.module	2 Jun 2010 13:40:44 -0000
@@ -1063,6 +1064,47 @@
+          '#default_value'  => $user->name,

I suspect this won't lead to display of the right original submission user if you edit a submission of someone else.

+++ webform.module	2 Jun 2010 13:40:44 -0000
@@ -1063,6 +1064,47 @@
+          '#parents'  => array( 0 => 'date' ), ¶

Trailing space

+++ webform.module	2 Jun 2010 13:40:44 -0000
@@ -1063,6 +1064,47 @@
+          '#default_value'  =>   date('Y-m-d h:m', time()),

Also: what about previous submissions on edit? I suspect this will update the creation time to edit time.

+++ webform.module	2 Jun 2010 13:40:44 -0000
@@ -1798,12 +1840,28 @@
+  ¶

Trailing space

+++ webform.module	2 Jun 2010 13:40:44 -0000
@@ -1798,12 +1840,28 @@
+    $submited_user = user_load(array('name' => $form_state['values']['author']));

submitted instead of submited (typo) please

+++ webform.module	2 Jun 2010 13:40:44 -0000
@@ -1798,12 +1840,28 @@
+	'uid' => $submited_uid,
+	'submitted' => $submited_time,

Tabs...

Powered by Dreditor.

alawneh86’s picture

Status: Needs work » Needs review
StatusFileSize
new3.69 KB

All issues are fixed.
now, you can change the submitting author and date if you have 'change submission author' or 'administer users' permissions.

miro_dietiker’s picture

Status: Needs review » Needs work

is it just me or...
what about the $form['#parameters'][3]->xyz
this looks so strange to me...
Is there no official way?
I was additionally looking at the webform code for the current form creation. See the following code from current webform.
I really think $submission should be available and therefore this would be the way to go instead of parameters.

1363	    $form['details']['uid'] = array(
1364	      '#type' => 'value',
1365	      '#value' => isset($submission->uid) ? $submission->uid : $user->uid,
1366	    );

In any other case the interfaces need cleanup.

alawneh86’s picture

Status: Needs work » Needs review
StatusFileSize
new3.17 KB

I used the $submission object to get the submitted author and date rather than $form['#parameters'][3].
and I added the author and date fields inside the 'webform_client_form' rather than 'hook_form_alter'.

alawneh86’s picture

StatusFileSize
new3.62 KB

providing validation on the author name.

khaled.zaidan’s picture

Assigned: alawneh86 » khaled.zaidan
StatusFileSize
new5.56 KB

Editing a submission by a user other than the original author, resulted in changing the author to the new submitter.
And editing a submission by a user who has no permission to change the submission date, resulted in changing the date to the current time.

Now it checks, if the user id is already set for an author and the user doesn't have permission to change the author, it keeps the original user id.
And also if the user doesn't have permission to change the submission date, no submission date is sent to the 'webform_submission_update($node, $submission)' call. 'webform_submission_update($node, $submission)' also had to be patched not to update the submission date of it is not specified.

miro_dietiker’s picture

Status: Needs review » Reviewed & tested by the community

OK, this now seems to work correctly.
From perspective of clean software code and simplicity:
I don't understand why in webform_client_form_submit() webform is not loading the submission from database using webform_get_submission() instead of building some arbitrary new object. Thus previous author of the submission would be present and no special case needed in webform.submission.inc webform_submission_update()

Not setting it to needs work as this is an architectural decision to be considered by the maintainer.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Needs work

there's a multipage issue. changes don't get persisted, get reverted and only get stored on the last page.

khaled.zaidan’s picture

StatusFileSize
new8.37 KB

Now the admin fieldset has it's own submit button. If editing an existing submission, it will be displayed on all pages, so the user doesn't need to go to the last page to change the author and/or date. If it's a new submission, it is only displayed on the last page.

Edit: of course there will be no separate submit button for new submissions, since the submission doesn't exist yet.

rsacchi’s picture

Very nice functionality, do you have plan to accomplish that in the version 6.x-3.0 of the webform ???

I'am needing something very similiar, but in the version 3x.

Thank you so much for this peace of code.

miro_dietiker’s picture

I was sure this was for 3.x ... no?

quicksketch’s picture

Version: 6.x-2.1.2 » 6.x-3.x-dev

Yeah I'm not sure why this is still in 2.x. New features are only being added 3.x.

rsacchi’s picture

You are right, my fault.
Thanks

pathaksumit’s picture

Is it possible to change to multiple user by adding any functionality in this patch??

shawn dearmond’s picture

There's still a problem where, when creating a new submission, the submitter sees the "Administration" fieldset on the second page of a multi-page webform. The submitter does have "change submission author" permission, but does not have "edit submissions" access to this webform.

Also, when the form is in "Draft" mode, the "Administration" fieldset appears.

shawn dearmond’s picture

StatusFileSize
new8.04 KB

Here's a re-rolled patch that fixes #23. I also cleaned up the comments a little.

shawn dearmond’s picture

Status: Needs work » Needs review

Needs Review

flightrisk’s picture

Was this ever included in webform?

quicksketch’s picture

No, if it were it would be marked "fixed" or "closed (fixed)". I'm still interested in the feature but it's not a high priority for me. Reviewing the patch and/or updating it will help move it forward. I marked your other issue #1540396: Can admin submit a form for another user? duplicate, since this is the feature that would be included, rather than a "submit as another user" feature.

flightrisk’s picture

I just realized this is useless to me. I am using the latest version 7 dev release. This patch is for version 6. The code is very different. Is there any chance I can get this patch for version 7 so I can test? Thanks.

flightrisk’s picture

Is there any update on this for Drupal 7? Thank you.

miro_dietiker’s picture

Assigned: khaled.zaidan » Unassigned

Khaled didn't participate for a long time.

quicksketch’s picture

Version: 6.x-3.x-dev » 7.x-4.x-dev
Status: Needs review » Needs work

This patch needs a reroll for the 7.x-4.x branch. The current patch also has some code formatting issues that could be addressed (whitespace vs. tabs). I'd appreciate a more polished UI than simply another collapsed fieldset, but I recognize that might not happen in the initial pass.

danchadwick’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

With the use of views to display the webform submissions and results (7.x-4.2+), I would suggest that you use VBO and and write an action to set the submission user and date. I don't see that this feature would go into webform core, although I would consider adding the actions. If this is an avenue that someone wants to proceed, along with providing some other actions (e.g. delete submission, maybe even download), please open a new issue.

coderintherye’s picture

StatusFileSize
new4.52 KB

Dan could you talk more about your reasons for not wanting this in the core of webform?
I could maybe see your logic for D8 since it includes views by default, but it's harder to parse for 7.x. especially with a viable solution at hand and one that is relatively well-contained change with minimal affect on the UI.

I'm attaching a re-rolled patch for 7.x that seemingly works (note it's done against my own repo so probably needs re-roll properly against webform repo) and could use some testing and perhaps further cleanup (might need some fudging as its against 3.x branch vs. 4.x but willing to re-roll against 4.x and add tests if you are open to this possibly making it in).

P.S. Left it as won't fix since you are the maintainer, but if you decide it's worthwhile please flip back to needs work or needs review. Thanks!

danchadwick’s picture

Your patch seems different from what was discussed above (bulk changing of multiple submissions).

I'm pretty sure you can accomplish this without hacking webform. You can use hook_webform_client_form_alter() to add the admin fieldset, and you can add a submit handler to adjust the author or date(s). Note that submissions now have 3 dates: first saved, first completed, last updated.

If lots of other people jump on this issue and shout with enthusiam, I could consider that an indicator that there is a broader use case than what I see. Absent that, I don't think this belongs in webform core.

mywebmasteruk’s picture

@coderintherye your patch on #33 does not seem to match the current webform.module 7.x 4.13
Can someone help me with an updated patch please?

or has anyone come up with a function from what Dan says in #34?

pixelshrink’s picture

I'd really like to see the author editable on webform.

robertgarrigos’s picture

I would love to see this into webform, I'm really enthusiast about it!! :-)

lordzik’s picture

Patch from #33 is in fact ok (7.x-4.19), only 3rd chunk needs to be applied manually.
What's wrong is that when submission is edited, the following error appear:

Warning: array_flip(): Can only flip STRING and INTEGER values! w DrupalDefaultEntityController->load() (linia 175 z /var/www/html/drupal7/includes/entity.inc).
Please specify a valid author.

Any chance to fix it?

commonpike’s picture

[deleted] ( I cant delete posts here :-) )