Skip to content

Instantly share code, notes, and snippets.

@vdespa
Created January 21, 2013 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdespa/4588583 to your computer and use it in GitHub Desktop.
Save vdespa/4588583 to your computer and use it in GitHub Desktop.
<?php
/**
* @copyright This is free software released into the public domain.
* @license GNU General Public License version 2 or later; see http://www.gnu.org/licenses/gpl-2.0.html
*
* Created based on the information found on:
*
* http://stackoverflow.com/questions/14285536/invalid-token-with-joomla-custom-component/14433783#14433783
* http://docs.joomla.org/How_to_add_CSRF_anti-spoofing_to_forms
*
* Copy this file inside components/com_recordings/
*/
defined('_JEXEC') or die;
class RecordingsController extends JControllerLegacy
{
public function display($cachable = false, $urlparams = false)
{
parent::display($cachable);
}
public function deletevideos()
{
JRequest::checkToken('get') or die('Invalid Token');
echo "Deleted!";
die;
}
}
<?php
/**
* @copyright This is free software released into the public domain.
* @license GNU General Public License version 2 or later; see http://www.gnu.org/licenses/gpl-2.0.html
*
* Created based on the information found on:
*
* http://stackoverflow.com/questions/14285536/invalid-token-with-joomla-custom-component/14433783#14433783
* http://docs.joomla.org/How_to_add_CSRF_anti-spoofing_to_forms
* Copy this file inside components/com_recordings/views/recordings/tmpl
*/
?>
<a href="#" id="delete">Click here to delete</a>
<p id="message"></p>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#delete").click(function(e){
e.preventDefault();
jQuery.ajax({
type: 'POST',
url: 'index.php?option=com_recordings&task=deletevideos&format=raw&<?php echo JUtility::getToken(); ?>=1',
success: function(data){
$("#message").html("<b>" + data + "</b>");
}
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment