2

I am using RS Forms Pro and I am able to view a list of submitted forms via a menu link. I am able to view, edit and download the forms from this page. I have since added delete functionality which works as expected. I followed the excellent guide here

What I am trying to do now is probably quite simple however I cannot figure it out.

When the 'delete' button is pressed, the form is deleted and the page refreshes, great. However I would like to display a message (presumably within the system-message div) that reads (something like)

successfully deleted

The delete functionality works however I will include my code for reference.

The script called on form display is as follows (this is set in RS Form config);

// First we have to check the "action" parameter from the URL
$action = JRequest::getWord('action');
if ($action == "delete") {

// If it returns true it will continue running the script 
  $id_value = JRequest::getInt('id');
  $formId_value = JRequest::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 = JRequest::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');
}

The code for my delete buton is as follows (override of com_rsform);

<a href="<?php echo JRoute::_('index.php?option=com_rsform&formId='.$this->params->get('formId').'&action=delete&id='.$item->SubmissionId);?>">delete</a>

When I view the page source I can see the empty div above my form where the system message would presumably go?

<div id="system-message-container"></div>

I understand this is related to RS Forms however I am wanting to understand how I pass a value to the system-message div upon successful deletion.

Suggestions welcome.

2

You can use the enqueueMessage function to display a message in the system output section.

In the code you've provided, you will see the following:

$mainframe->redirect(JRoute::_('index.php?option=com_rsform&view=directory&Itemid='.$itemId_value, false));

Replace it with the following:

$mainframe->redirect(JRoute::_('index.php?option=com_rsform&view=directory&Itemid='.$itemId_value, false), 'successfully deleted', 'success');

For ease of view:

$url  = 'index.php?option=com_rsform&view=directory&Itemid='.$itemId_value;
$msg  = 'successfully deleted';
$type = 'success';
$mainframe->redirect(JRoute::_($url, false), $msg, $type);

Update:

Sorry, it turns out that passing a message in the redirect function is deprecated. Instead, enqueueMessage should be used before the redirect, like so:

$url  = 'index.php?option=com_rsform&view=directory&Itemid='.$itemId_value;
$msg  = 'successfully deleted';
$type = 'success';
$mainframe->enqueueMessage($msg, $type);
$mainframe->redirect(JRoute::_($url, false));
  • @johnny_s - You're welcome as always ;) – Lodder Jun 29 '15 at 15:29
  • @johnny_s - See my update – Lodder Jun 30 '15 at 9:35
  • your first answer works though? Is is simply depreciated - but will still work? – jonboy Jun 30 '15 at 9:39
  • 1
    @johnny_s - Yup, my first code snippet will still work, it's just simply deprecated and will probably be removed in Joomla 4.0 which is ages away – Lodder Jun 30 '15 at 9:46

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.