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?

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.

  • 1
    Thank you! This is what I used: $submission = webform_menu_submission_load($sid, $nid); $node = node_load($nid); webform_submission_delete($node, $submission); – Brian Reeves Mar 20 '12 at 4:56
  • Nice! Good to know that you were able to solve your issue fast. – amateur barista Mar 20 '12 at 5:06
  • This answer is not correct. Both parameters must be objects, as BWagner said in his answer. – mbomb007 Dec 19 '18 at 22:51
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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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