After creating database, we need a friendly interface for adding data. Now, we create simple form for inputing data.
- Open "admin.hello.php" within joomla/administrator/components/com_hello.
- Replace with following code:
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
// to include admin.hello.html.php
require_once( JApplicationHelper::getPath( 'admin_html' ) );
$task = JRequest::getCmd('task');
// checks the $task variable and
// choose an appropiate function
switch($task){
case 'add':
addHello();
break;
case 'cancel';
cancelHello();
break;
default:
showHello();
break;
}
function addHello(){
$lists['published'] = JHTML::_('select.booleanlist', 'published' , 'class="inputbox"', $row->published);
// display function
HTML_contact::addHello($lists);
}
function showHello(){
// display function
HTML_contact::showHello();
}
?>
- Now, create the admin.hello.html.php file and add the following code:
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
class HTML_contact
{
function addHello($lists){
JRequest::setVar( 'hidemainmenu', 1 );
$editor =& JFactory::getEditor();
?>
<script language="javascript" type="text/javascript">
<!--
function submitbutton(pressbutton) {
var form = document.adminForm;
if (pressbutton == 'cancel') {
submitform( pressbutton );
return;
}
submitform( pressbutton );
}
//-->
</script>
<form action="index.php" method="post" name="adminForm">
<table class="admintable">
<tr>
<td class="key">
<label for="message">
<?php echo JText::_( 'Message' ); ?>:
</label>
</td>
<td >
<?php
echo $editor->display('message','','100%','250','40','6');
?>
</td>
</tr>
<tr>
<td class="key">
<label for="message">
<?php echo JText::_( 'Published' ); ?>:
</label>
</td>
<td >
<?php
echo $lists['published'];
?>
</td>
</tr>
</table>
<input type="hidden" name="option" value="com_hello" />
<input type="hidden" name="task" value="" />
</form>
<?php
}
function showHello(){
echo "Hello, World!";
}
}
?>
Now, point your browser to http://localhost/joomla/administrator/index.php?option=com_hello&task=add
All toolbar still not active, but cancel. Next tutorial, we will learn how to save data to database using save/apply button.