[solved] My First Admin Module

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
cd163601
Forum Members
Forum Members
Posts: 14
Joined: Wed Aug 12, 2009 8:03 pm

[solved] My First Admin Module

Post by cd163601 »

I've made my first module, I am trying to improve it to use the provided classes properly.  I am only looking at the Admin side and I want to be able to save preferences and add items to an SQL Table.

I have got the Install and Uninstall modules working, creating and dropping the SQL tables, setting some default preferences and creating permissions.

I have created an action.adminDefault.php and I have successfully created Tabs in the Admin interface. The first tab for example says:

Code: Select all

echo $this->StartTab('sendmail', $params);
include dirname(__FILE__).'/function.sendmail.php';
echo $this->EndTab();
So I now have a "function.sendmail.php" which says

Code: Select all

$smarty->assign('startform', $this->CreateFormStart($id, 'sendemail'));
$smarty->assign('endform', $this->CreateFormEnd());
...
$smarty->assign('title_subject', $this->Lang('subject'));
$smarty->assign('input_subject', $this->CreateInputText($id,'formsubmit_subject','',50,128));
...
$smarty->assign('submit', $this->CreateInputSubmit($id, 'sendmail_submitbutton', $this->Lang('send')));
echo $this->ProcessTemplate ('admin_sendmail.tpl');
So I have a "templates/admin_sendmail.tpl" file that has

Code: Select all

{$startform}
<div class="pageoverflow">
	<p class="pagetext">{$title_subject}:</p>
	<p class="pageinput">{$input_subject}</p>
</div>
<div class="pageoverflow">
	<p class="pagetext"> </p>
	<p class="pageinput">{$submit}</p>
</div>
{$endform}
I now successfully have an admin page that has a single input box and a submit button.

My question is, where do I put my code to pick up the results of the Submit? What procedure/file do I use to get the inforamtion that was put in the 'sendmail_subject' input box?

Many thanks
Colin
Last edited by cd163601 on Mon Sep 28, 2009 2:44 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: My First Admin Module

Post by calguy1000 »

$smarty->assign('startform', $this->CreateFormStart($id,'sendemail'));

The CreateFormStart method asks for an 'action' parameter, in this case you've specified 'sendemail'
so the proper solution would be to create your form handling code in action.sendemail.php
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
cd163601
Forum Members
Forum Members
Posts: 14
Joined: Wed Aug 12, 2009 8:03 pm

Re: My First Admin Module

Post by cd163601 »

Thank you for the reply.  Using the News module as an example, I have put the following code into the action.sendmail.php file.

Code: Select all

<?php
$this->Audit( 0, $this->Lang('friendlyname'), $this->Lang('emailsent').' '.$params['formsubmit_to']);
$params = array('tab_message'=> $params['formsubmit_subject'], 'active_tab' => 'sendmail');
$this->Redirect($id, 'defaultadmin', '', $params);
?>
I was expecting it to log to the admin log and then redirect to my (working) sendmail tab from my module with a message equal to whatever was entered into the formsubmit_subject input box.

But instead it is going to a blank admin page with just "Send Email" in the title and no tabs at all and does not log to the admin log.

I am now very confused.

Thanks
Colin
cd163601
Forum Members
Forum Members
Posts: 14
Joined: Wed Aug 12, 2009 8:03 pm

Re: My First Admin Module

Post by cd163601 »

Sorry, I have got it working, I misspelt the action.sendmail.php file.

That's brilliant, thank you.

Regards
Colin
Post Reply

Return to “Developers Discussion”