2

I want to delete a webform submission from a custom module that I've written. I'm using webform_submission_delete(123, 76). The error I receive is:

Notice: Trying to get property of non-object in webform_submission_delete() (line 141 of /Applications/MAMP/htdocs/mercury/sites/all/modules/webform/includes/webform.submissions.inc). Warning: Invalid argument supplied for foreach() in webform_submission_delete() (line 141 of /Applications/MAMP/htdocs/mercury/sites/all/modules/webform/includes/webform.submissions.inc). Notice: Trying to get property of non-object in webform_submission_delete() (line 153 of /Applications/MAMP/htdocs/mercury/sites/all/modules/webform/includes/webform.submissions.inc). Notice: Trying to get property of non-object in webform_submission_delete() (line 157 of /Applications/MAMP/htdocs/mercury/sites/all/modules/webform/includes/webform.submissions.inc).

I'm a bit new to module development. Am I missing something?

4 Answers 4

5

If you are calling this webform_submission_delete() function, then both the first and second parameters must be objects. At least the first parameter is a node object. Most likely you are calling this using:

$nid = 12345;
webform_submission_delete($nid, $sid);

instead of doing

$node = node_load(12345);
webform_submission_delete($node, $sid);

and as a result causing PHP to complain.

If you have doubts on how to implement webform_submissions_delete(), I suggest you take a look at the various functions that implement it for an example.

5
  • 1
    Thank you! This is what I used: $submission = webform_menu_submission_load($sid, $nid); $node = node_load($nid); webform_submission_delete($node, $submission); Commented Mar 20, 2012 at 4:56
  • Nice! Good to know that you were able to solve your issue fast. Commented Mar 20, 2012 at 5:06
  • This answer is not correct. Both parameters must be objects, as BWagner said in his answer.
    – mbomb007
    Commented Dec 19, 2018 at 22:51
  • What about in D9?
    – Matoeil
    Commented Dec 1, 2021 at 14:18
  • the links are outdated
    – Matoeil
    Commented Dec 1, 2021 at 15:36
1

Or if you would like to just do it via an external module you could also use the Webform_clear module

1

This is ancient now, but for future posterity:

As amateur barista suggests, you need to pass the objects, not just the ids. For BOTH node and submission.

webform_submission_delete($node, $submission)
0

in drupal9 webform provides an option to delete the submission after a certain days

/admin/structure/webform/manage/{my webform name}/settings/submissions

enter image description here

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.