[SOLVED] Can't get my "delete" method working in Admin section

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
F80
New Member
New Member
Posts: 7
Joined: Mon Sep 06, 2010 10:02 am

[SOLVED] Can't get my "delete" method working in Admin section

Post by F80 »

Hi all,

I'm working on my first module (and it's tough..), which generates a tagcloud based on tagwords that are taken out of a database. So far, everything works except the deletion part.

In my admin section I have two tabs: Add and Delete. The Add tab has a small inputbox and a submit button which works (although it doesn't return to the default tab after you entered something, but that's my least concern). In the Delete tab, all the keywords are gathered from the database and displayed in tabular format with a submit button (for deletion). If I press on a delete button, I get an empty screen in the adminsection (meaning that all the adminsections, like backgroundcolor, menu, and text) are there, but the spot where the module settings are is empty. If I go back to the list then, nothing is deleted.

This is the code for action.defaultadmin.php

Code: Select all

if( !isset(cmsms()) ) exit;
// choose the tab to display. If no tab is set, select 'shows' as the default
// tab to display, because - in my opinion - this is the mostly needed tab.
if (!empty($params['active_tab']))
  $tab = $params['active_tab'];
else
  $tab = 'toevoegen';

// and finally, display all those tabs. First, setup the tabs, and than include
// the function.{tab}.php file, in which the tab's code is stored to keep this
// file a bit tidier.
echo $this->StartTabHeaders();
	echo $this->SetTabHeader('toevoegen', 'Toevoegen', 'toevoegen' == $tab ? true : false);
	echo $this->SetTabHeader('verwijderen', 'Verwijderen', 'verwijderen' == $tab ? true : false);
echo $this->EndTabHeaders();

// Display each tab's content
echo $this->StartTabContent();
	echo $this->StartTab('toevoegen');
		echo $this->CreateFormStart($id, 'process', $returnid);
			echo $this->CreateInputHidden($id, "method", "insert");
			echo $this->CreateInputText($id, "tag", "", "20");
			echo $this->CreateInputSubmit($id, "submit", "Toevoegen");
		echo $this->CreateFormEnd();
	echo $this->EndTab();
	
	echo $this->StartTab('verwijderen');
		$values = array();
		$values = $this->_Load_Tags();
		
		echo $this->CreateFormStart($id, 'process', $returnid);
		echo $this->CreateInputHidden($id, "method", "delete");
		
		echo "<table>";
		foreach ($values as $key => $value)
		{
			echo "<tr>";
				echo "<td width='100px'>";
					echo $value;
				echo "</td>";
				
				echo "<td>";
					echo $this->CreateInputHidden($id, "id", $key);
					echo $this->CreateInputSubmit($id, "submit", "Verwijderen");
				echo "</td>";
			echo "</tr>";
		}
		echo "</table>";
		echo $this->CreateFormEnd();
		
	echo $this->EndTab();
echo $this->EndTabContent();
and the code for action.process.php

Code: Select all

if( !isset(cmsms()) ) exit;
	if (isset($params['method']) || isset($params['meth']))
	{
		if ($params['method'] == "insert")
		{
			$tag = $params['tag'];
			
			$insert_SQL = "Insert Into ins_tagcloud (tag) Values ('" . $tag . "')";
			$insert_result = mysql_query($insert_SQL) or die (mysql_error());
			
			$this->Redirect ($id, 'defaultadmin', $returnid);
		}
		elseif ($params['method'] == "delete")
		{
			$id = $params['id'];
			
			$delete_SQL = "Delete From ins_tagcloud Where id = '" . $id . "'";
			$delete_result = mysql_query($delete_SQL) or die (mysql_error());
			$this->Redirect ($id, 'defaultadmin', $returnid);
		}
	}
	else
	{
		$this->Redirect ($id, 'defaultadmin', $returnid);
	}
Thanks in advance!
Last edited by F80 on Fri Oct 22, 2010 7:16 am, edited 1 time in total.
NaN

Re: Can't get my "delete" method working in Admin section

Post by NaN »

the var $id is already used by the CMS.
You may not override it.
Try another var name.
F80
New Member
New Member
Posts: 7
Joined: Mon Sep 06, 2010 10:02 am

Re: Can't get my "delete" method working in Admin section

Post by F80 »

yeah I think your right, I changed some little things yesterday and now it's finally working, and one of the changed things was the use of another var instead of $id... thanks anyhow!
Post Reply

Return to “Developers Discussion”