Is it possible to remove the submissions from the submissions tab as l envisage that this will be come massive after a few months?
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
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
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
Anyone able to help with any of these requests?
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
Ok, so can you point me in the right direction for this as l am by no means a programmer?
I think the better idea would be to make it a TableListField:
http://doc.silverstripe.com/doku.php?id=tablelistfield
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
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