Is it possible to automatically send an email out when a submitted form has been revised?

CommentFileSizeAuthor
#10 Picture 2.png18.52 KBjpsimon
#8 Picture 1.png34.45 KBjpsimon

Comments

richardp’s picture

That's not a bad idea. I honestly don't know if there is already a way to do that without any additional programming (as in, it might already be possible to have Webform send an email when any submission is made, revision or otherwise). I will check around and see what I can find.

Thanks for your interest in the module!
Richard

vernond’s picture

Nice module richardp!

To sort out the emailing request, could you not job the parameters and call webform_client_form_submit($form, &$form_state) directly from webform_revisions_confirm_revert_revision_submit to achieve the aim?

Alternatively, I guess, one could duplicate the relevant mail building and sending code from webform_client_form_submit and exclude the chunks of validation (the revisions would already have passed through that). It's not as tidy, but it would process a lot faster than going back through the submit cycle.

[edit] (Yup, that's right, I'm too lazy to test the idea myself!)

jpsimon’s picture

I'll be the first to admit I have no idea what I'm doing, but I'll give that whirl and report back

/edit/ yeah, my previous statement holds true. I can't figure out how to make that work. Richard, think you could give it a try when you have a little time?

richardp’s picture

Sure thing. I'm sorry I haven't responded before now, my work has been keeping me fairly busy. I am actually going to be working on this module as part of my real job, so I should have a chance to check it out. Just so I understand the request fully-- the idea is that I set "bob@example.com" to receive an email when the webform is submitted. I do this using Webform's interface. Then, when someone edits a revision, bob@example.com gets emailed again?

I am imagining controls for this functionality being on a settings page on a per-webform basis. As in, I could see how a site with several webforms might only want some of them to email-on-revision, and some not. So I would let that be configurable per webform.

Richard

jpsimon’s picture

Yep exactly! The most ideal setup in a perfect world would be sending only the edited fields in this revision email. I guess a perfect revision email would have a link to the revised submission, who edited it, and the fields which were edited. Not sure if that is feasible, but definitely an "ideal/perfect" solution.

That being said, just re-sending the whole thing would be fantastic in itself. I have it so fields which are empty (optional fields which a user didn't fill in) do not get sent in the email. If we're just resending the whole thing, would this still apply? The code is located in my theme template.php file:

function mytheme_webform_element_text($element, $value) {
  if (strlen(trim($value)) == 0) {
    return '';
  }

  return theme_webform_element_text($element, $value);
}  

Again, thank you for the great module and your help!!

richardp’s picture

Version: 6.x-1.0-alpha2 » 6.x-1.0-beta1

Okay, I've got a new version for you: beta1. The only way I could find to send an email using the existing Webform email settings was just to take advantage of the Webform code which sends emails. It seemed to be the most straightforward and logical option. As such, when you submit a revision, it just sends the entire email again, to whichever recipient(s) you have specified. In order to enable this, though, you must go to the settings page for Webform Revisions (admin/settings/webform-revisions) and turn it on per-form. It is turned off by default.

One important caveat: this only works with the 3.x branch of webform. Not version 2.9. I looked and there is just no way I can make webform resend the email in that version. But since they are now on 3.4, I think this requirement will be less obtrusive over time.

Also in this new version-- you can leave revision log comments per revision, just like with Drupal's regular revision system. One caveat: you cannot do this with the initial submission, only with the submission of revisions, though this might be something I can tweak if there is a demand for it.

This did require a database change, so if you are upgrading, be sure to run Update.

Thanks for the good feature idea!
Richard

jpsimon’s picture

You're a life saver man! I'll give this a try tomorrow when I get to work.

jpsimon’s picture

StatusFileSize
new34.45 KB

Just tried it, the email re-sends correctly but I get the attached errors. Does that have anything to do with this new version of webform_revisions? I hadn't seen those errors before.

How hard would it be to only send the revised field(s) in the email, or highlight them in some way - make them bold?

richardp’s picture

Hmm. I don't recognize the errors. What happens when you send it but do not try to send the email? (Configured on the admin settings form)? Do you still get the errors?

What version of webform are you using?

jpsimon’s picture

StatusFileSize
new18.52 KB

When I don't send the re-submit email, it gives only these two errors (attached). I'm using webform version 6.x-3.4

richardp’s picture

Huh. Well, that is weird, but I think I see the issue. Those are "notices" and not "warnings", which is probably why I never saw them on my screen. Just out of curiosity, try disabling Webform Revisions entirely and see if they are still there. Given the location of the notices, I'm not sure if that is being caused by my module at all, or if it is in the Webform module. Did you just upgrade to 3.4?

This may sound a little kludgy, but you could just tell it not to report notices on screen. I am just using the default installations of everything, with no modifications, and mine doesn't report notices. My system only ever reports Warnings and Errors.

Of course, if there is anything I can do in my module to keep the notices from showing, I will of course try.

jpsimon’s picture

When I disable webform_revisions those warnings do not show up.

The functionality is there and works properly, so in the end I can just hide the warnings if it's too much of a needle-in-a-haystack kind of search for the issue

richardp’s picture

Hmm. Well, if does sound like my issue. I guess when a re-submit the form, it is expecting certain indexes to be there in the array which are not.

I will check around and see if I can figure it out.

Thanks
Richard

jpsimon’s picture

I had an idea - sort of going off needing to display only the edited fields in the revision email. I was thinking of just having a "revision notes" textarea field in the form itself. When a user edits their submitted form, they will edit that one field and write the specific changes in.

Is there a way to only send that one specific field in the revision email? That way only these revision notes comes to the user and you don't need to figure out which of the previous fields were changed

richardp’s picture

Well, the reason I have to send everything is because there is a lot of logic that goes into sending an email, since you can change who gets what based on what they entered into certain webform fields. This is all handled by the webform module itself, in a secure way. I don't want to try to duplicate that myself, so that if updates, security fixes, etc, are made to the webform module, I won't have to also keep up with those changes in my module. So, I just rely on webform's functions to send the email. And after looking around, there doesn't appear any way for me to tell the webform module to only send certain fields on re-submit of a revision.

It sounds like you need a very specific solution to a project you are working on. As such, I think you need to take matters into your own hands, so to speak, and need create a custom module to do what you are looking for.

I do have a notes textarea on each revision already. It sounds like you could create a custom submit handler, grab just that one field, and email it to whomever it is you need to email it to from there with a simple PHP mail() call. Just theorizing ;)

Richard

jpsimon’s picture

fair enough! thanks again for the help, simply emailing the whole form after a revision is 99% of what I needed. the rest is just icing on the cake

richardp’s picture

Status: Active » Closed (works as designed)

No problem!

Thanks,
Richard