Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Remove Submissions


Reply


8 Posts   2154 Views

Avatar
lukehumble

17 Posts

29 October 2007 at 9:28am

Is it possible to remove the submissions from the submissions tab as l envisage that this will be come massive after a few months?

Avatar
Sean

Forum Moderator, 922 Posts

1 November 2007 at 12:30am

Edited: 01/11/2007 10:29pm

Hi there,

Good request. It's certainly not too difficult to achieve this.

First of all, edit UserDefinedForm.php, and add this method into it (preferably just around where the current delete() function is, above or below).

/**
* Remove a submitted form.
*
* This only breaks the relation, leaving the record in the database.
* Permission checks stop non-administrators from accessing this method.
*/
function deletesubmission() {
if(Permission::check('ADMIN')) {
if($submissionID = Director::urlParam('ID')) {
if($submission = DataObject::get_by_id('SubmittedForm', (int)$submissionID)) {
$this->Submissions()->remove($submission);
}
}
Director::redirectBack();
} else {
Security::permissionFailure($this, 'You must be an administrator to perform this action');
}
}

Secondly, we need to add a link in the template so you can click to delete a submission in the interface. Open up SubmittedFormReportField.ss and add this line, just below the line 'Submitted at...'

<a href="{$Parent.Link}deletesubmission/$ID">Delete this submission</a>

Then you should be all done. :-)

I'll see about putting something like this in the actual SS release, so it's a default piece of functionality out of the box in SilverStripe.

Cheers,
Sean

Avatar
lukehumble

17 Posts

2 November 2007 at 4:51am

Edited: 02/11/2007 6:18am

Great, thanks for that!
Works beautifully but l have spotted a little irritating occurance:

When l delete a submission it refreshes the page and takes me back to the "content" tab instead of the "submissions" tab, anyway we can stop this so it stays on the submissions tab?

Other suggestions:
+ Reverse the display order so the most recent are displayed at the top.
+ Perhaps have tick boxes to select all the messages to delete then click delete.
+ Export submission as a spreadsheet of some description (would love this).
+ Add pagenation so that there is only "x" amount displayed per page.

Anyway, once again thanks for the help as this is great!
Regards,
Luke

Avatar
lukehumble

17 Posts

14 November 2007 at 11:12pm

Anyone able to help with any of these requests?

Avatar
Nicolaas

Forum Moderator, 213 Posts

3 December 2007 at 9:38am

Hi,

I think it would be a good idea to make it an AJAX function. I cant give you the exact recipee, but it will not be hard.

Cheers

Nicolaas

Avatar
lukehumble

17 Posts

4 December 2007 at 12:36am

Ok, so can you point me in the right direction for this as l am by no means a programmer?

Avatar
Sean

Forum Moderator, 922 Posts

4 December 2007 at 12:47am

Edited: 04/12/2007 12:56am

I think the better idea would be to make it a TableListField:

[url]http://doc.silverstripe.com/doku.php?id=tablelistfield[/url]

All the features of pagination, sorting, filtering, AJAX, and CSV export are included. I think it may be feasible to implement this in the submissions somehow. Although not entirely sure how it would work in terms of dynamic admin editable form fields as columns in the table. Could be a bit messy...

You see, the problem is if someone adds a couple of fields in their form... runs it for a while and receives a few submissions, then decides to add a few more fields, receiving further submissions after the change, then the submissions become out of sync (some fields not filled out by earlier submissions etc.).

It's a bit of a challenge to solve something like this, especially when it comes to exporting out submission data! :-)

Sean

Avatar
mjxxx

2 Posts

5 December 2007 at 6:01pm

Sean,

Your code modification for "UserDefiniedForm.php" works great.

Is there a benefit to having the "deleted submission" remain in the database (breaking the relative) VS deleting it entirely?

Could you please provide sample code for breaking the relation (removing the submission) and deleting it from the database?

Apologies in advance if this is simple and I am overlooking how to achieve it.

Thanks in advance.

Michael