Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Remove Submissions

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

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

Page: 1
Go to End
Author Topic: 2081 Views
  • lukehumble
    Avatar
    17 Posts

    Remove Submissions Link to this post

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

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Remove Submissions Link to this post

    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

  • lukehumble
    Avatar
    17 Posts

    Re: Remove Submissions Link to this post

    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

  • lukehumble
    Avatar
    17 Posts

    Re: Remove Submissions Link to this post

    Anyone able to help with any of these requests?

  • Nicolaas
    Avatar
    Forum Moderator
    213 Posts

    Re: Remove Submissions Link to this post

    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

  • lukehumble
    Avatar
    17 Posts

    Re: Remove Submissions Link to this post

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

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Remove Submissions Link to this post

    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

  • mjxxx
    Avatar
    2 Posts

    Re: Remove Submissions Link to this post

    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

    2081 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.