Page 1 of 1

[solved] My First Admin Module

Posted: Fri Sep 25, 2009 12:55 pm
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

Re: My First Admin Module

Posted: Fri Sep 25, 2009 1:03 pm
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

Re: My First Admin Module

Posted: Fri Sep 25, 2009 7:48 pm
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

Re: My First Admin Module

Posted: Mon Sep 28, 2009 2:44 pm
by cd163601
Sorry, I have got it working, I misspelt the action.sendmail.php file.

That's brilliant, thank you.

Regards
Colin