Joomla - Component: Creating Form Input Data at Back End


After creating database, we need a friendly interface for adding data. Now, we create simple form for inputing data.

  1. Open "admin.hello.php" within joomla/administrator/components/com_hello.
  2. 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();
    }
    
    ?>
    
  3. 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

joomla: form input data All toolbar still not active, but cancel. Next tutorial, we will learn how to save data to database using save/apply button.


Series this article:
Joomla - Component: Create Hello World Component on Front End
Joomla - Component: Create Hello World Component on Back End
Joomla - Component: Registering Your Component in database
Joomla - Component: Create Component Link for Front End
Joomla - Component: Creating Toolbars
Joomla - Component: Available Toolbar Buttons
Joomla - Component: Creating the Database Table
Joomla - Component: Creating Form Input Data at Back End
Joomla - Component: Saving Data to Database
Joomla - Component: Creating a List Screen
Joomla - Component: Creating Advance List Screen
Joomla - Component: Editing Data
Joomla - Component: Deleting Data
Joomla - Component: Updating publish state
Joomla - Component: Hello From Database at Front End
Joomla - Component: a Hello page
Joomla - Component: Generating Friendly Links
Joomla - Component: Adding Comment ( Create Table )
Joomla - Component: Adding Comment (Create Form)
Joomla - Component: Adding Comment ( Insert Data )
Joomla - Component: Adding Comment ( Displaying Comments )
Joomla: Fast Road to Understand Component Programming

Bookmark and Share Tag: joomla, cms, Joomla Component Category: PHP Framework Post : November 04th 2007 Read: 87,412

advertisements


blog comments powered by Disqus