Forum Moderators: open
I have a list of content items that is grabbed from a mysql database through a loop in PHP. For each content item, I have a checkbox. want I found I really needed, was the option to change the forms action URL with Javascript, so I dug up a script to do so...
function OndeleteContent()
{
document.contentForm.action = "?task=content&action=delete_content"
document.contentForm.target = "_self"; // Open in a new window
document.contentForm.submit(); // Submit the page
return true;
}
Thats the Javascript I use for deleting items. Should work in conjunction with this ...
<form name="contentForm" method="post" action="">
<input type="image" src="templates/images/delete_content.gif" alt="Delete Content" class="contentOption" name="OndeleteContent" onclick="return OndeleteContent();">
The Javascript and image submit sends me to the appropriate page, but doesnt appear to be sending any of the data with it. I checked to see if the form submittion was set through PHP, else return a message "Not set" and I costantly retrive Not Set message. Not sure if this is a PHP error or something with the Javascript, but here is also a small bit of the PHP...
if (isset($_POST['OndeleteContent']))
{
foreach($_POST['checkbox'] as $id)
{
$sql = "DELETE FROM content WHERE id = '$id'";
$result = mysql_query($sql) or die("Error in Query");
}
}
else {
echo "Not set";
}
Can anyone help diagnose this issue? If it helps, I have other options to edit items, publish, and unpublish items, which are all controlled by similar methods (Javascript functions). I would link to live example, but I am testing locally through XAMPP.