I would like to log failed submissions with the reason for failure. In my application, anonymous users are vetted through a short webform that asks basic questions of a potential job applicant. If they don't meet the minimum requirements, the webform is not 'created' and the usual error message is returned to the applicant. It would be useful to log failed attempts so we can see what areas are typical for deficiencies. It could help us out in the long run.
I hacked the webform_validation.module webform_validation_validate() function (yes, I know that's a big no-no!). I have taken the module out of the update loop so I can get the failed submissions logged and not worry about an overwrite of the module during an update. I am a total PHP novice and it is probably most inelegant, but it gets the job done in three lines. Mod starts at line 168 in webform_validation.module:
if ($errors) {
$errors = webform_validation_unprefix_keys($errors);
$components = webform_validation_unprefix_keys($component_definitions);
foreach ($errors as $item_key => $error) {
// build the proper form element error key, taking into account hierarchy
$error_key = 'submitted]['. webform_validation_parent_tree($item_key, $components) . $components[$item_key]['form_key'];
// JJE 6/6/11 - create watchdog message
$logmessage = webform_validation_parent_tree($item_key, $components) . $components[$item_key]['form_key'] . " failed min-req.";
// JJE 6/6/11 - send watchdog message
watchdog("Webform Min Req", t($logmessage), NULL, WATCHDOG_NOTICE, NULL);
// JJE 6/6/11 - end watchdog message
form_set_error($error_key, $error);
}
It would be nice to have a switch somewhere to turn on or off logging functions for failed webform submissions. I am not yet skilled enough to do that, but am willing to learn from the masters.
Any takers?
Comments
Comment #1
svendecabooterI will have to look into the best approach to allow this functionality, and make it generic enough... Perhaps i'll introduce a new hook that gets called for each form error, so other modules can react on that action (where logging it to watchdog would be one of the unlimited number of options).
I'm also planning an architectural rebuild of this module, so perhaps that's something that will go there, rather then in the current branch.
To be continued, but currently i'm flooded with client work, so it'll have to wait until my schedules allows it :)
Thanks for your suggestion
Comment #2
liam morlandDrupal 6 is no longer supported. If this issue exists in a later version of webform_validation, please re-open and update the version number.
Comment #3
liam morland