How to create a delete submission button in Manage directories
In this article we will explain how to create a button in the Manage directories layout to delete submissions
- First of all we will create a language override to create an error in case conditions are not met.
- Next on the to do list is a template override for the Submission directory layout
- Copy default_layout.php from /components/com_rsform/views/directory/tmpl
- To /templates/template_name/html/com_rsform/directory (NOTE: Match the folder structure)
- Add to the newly copied default_layout.php, after line 39 (NOTE: It has to be after line 39 so it can be available only to the users with edit permissions):
- Now we have to create a script to check the paramenters and delete the submission values for that specific submission id
To do this head over to Extensions > Language Manager > Overrides > New button
In the first field (Language Constant) we will give a name to the override, in this case :
"RSFP_DELETE_ERROR"
The second field is the text you want to be displayed when it's executed, for this example we will use :
"You are not authorized to delete this submission."
After adding the desired text in the fields, click Save & Close
<a href="<?php echo JRoute::_('index.php?option=com_rsform&formId='.$this->params->get('formId').'&action=delete&id='.$item->SubmissionId); ?>">Delete</a>
Basically this line is a link to your form, with 2 custom parameters : action and submission id
Head over to Components > RSForm!Pro > Manage Forms > Select the form > Properties > PHP scripts > And insert in the Scripts called on form display the following:
// First we have to check the "action" parameter from the URL $paramsURL = JFactory::getApplication()->input; $action = $paramsURL->getString('action'); if ($action == "delete") { // If it returns true it will continue running the script $id_value = $paramsURL->getInt('id'); $formId_value = $paramsURL->getInt('formId'); // For security reasons we verify if the user has the right to edit submissions using RSFormProHelper if ($id_value && $formId_value && RSFormProHelper::canEdit($formId_value,$id_value)){ // If user has enough permission rights, run the query $db = JFactory::getDbo(); $db->setQuery("DELETE FROM #__rsform_submission_values WHERE `SubmissionId`='". $id_value."'"); $db->execute(); $db->setQuery("DELETE FROM #__rsform_submissions WHERE `SubmissionId`='". $id_value."'"); $db->execute(); // Redirect the user back to Manage directories $itemId_value = $paramsURL->getInt('Itemid'); $mainframe->redirect(JRoute::_('index.php?option=com_rsform&view=directory&Itemid='.$itemId_value, false)); } // If the user does not have permission to edit, he will be prompted with the language override created earlier: else $formLayout = JText::_('RSFP_DELETE_ERROR'); }
12 persons found this article helpful.
You Should Also Read
How to enable submission confirmation HOT |
How to add a print button in the View Submissions area HOT |
How to modify the submission time stamp format, common format examples |