PHPEveryday.com PHP and Web Development Tutorial
What are you looking for?


PHP Error Message

Warning: Invalid argument supplied for foreach() in /home/a3178292/public_html/article.php on line 213

Free Web Hosting

Joomla - Component: Editing Data


After create list screen, now we will build form editing data. You can edit a data by click id row in list table. Then, form editing data will display. Click save or apply button to save data.

  1. Open "admin.hello.html.php" file, and add following bold code to showhello():
        <?php
    	
        $k = 0;
    	for($i=0, $n=count($rows); $i < $n ; $i++)
    	{
    $row = &$rows[$i];
    $checked 	= JHTML::_('grid.id', $i, $row->id);
    $published 	= JHTML::_('grid.published', $row, $i); 
    // prepare link for id column
    $link 		= JRoute::_( 'index.php?option=com_hello
    &task=edit&cid[]='. $row->id );
    ?<
    <tr class="<?php echo "row$k"; ?>">
    <td><?php echo $checked?></td>
    // show link, that will clicked to go to edit form page
    <td><a href="<?php echo $link; ?>">
        <?php echo $row->id?></a></td>
    <td><?php echo $row->message?></td>            
    <td><?php echo $published?></td>            
    </tr>
            <?
    $k = 1 - $k;
    	}
    	?>
    
  2. Add editHello() function:
    	function editHello(&$lists, &$row){
    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',
    $row->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="id" value="<?php echo $row->id?>" />        
    <input type="hidden" name="cid[]" value="<?php echo $row->id; ?>" />        
    <input type="hidden" name="task" value="" />        
    </form>
            <?php		
           }	
    
  3. Open "admin.hello.php", add following code: $task = JRequest::getCmd('task'); $id = JRequest::getVar('id', 0, 'get', 'int');
  4. update like following code:
    switch($task){
    
      case 'edit':
        editHello();
        break;
    
      case 'add':
        addHello();
        break;
    		
      case 'cancel';		
        showHello();
        break;
    		
      case 'save';	
        case 'apply';	
        saveHello();
        break;		
    		
      default:
        showHello();
        break;
    
    }
    
  5. Add editHello() function:
    function editHello()
    {
    	$db		=& JFactory::getDBO();
    
    	$cid 	= JRequest::getVar('cid', array(0), '', 'array');
    	JArrayHelper::toInteger($cid, array(0));
    	
    	$id 	= $cid[0];
    
    	$row =& JTable::getInstance('hello', 'Table');
    	// load the row from the db table
    
    	$row->load( $id);
    	
    	$lists = array();
    	$lists['published'] = JHTML::_('select.booleanlist', 'published' , 'class="inputbox"', $row->published);
    
    	// display function 
    	HTML_contact::editHello(&$lists, &$row);
    }
    
  6. Last, open "toolbar.hello.php". update like following code:
    switch ( $task )
    {
    	case 'add'  :
    	case 'edit'  :	
    		TOOLBAR_hello::_NEW();
    		break;
    
    	default:
    		TOOLBAR_hello::_DEFAULT();
    		break;
    }
    


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


Tag: joomla, cms, Joomla Component Category: PHP Framework Post : November 05th 2007 Read: 12,418 Bookmark and Share

blog comments powered by Disqus


Database Tutorial
  • Learn PHP MySQL
  • Learn PHP ADOdb
  • Learn PHP Data Object/PDO
  • Learn PHP XML
  • Learn PHP SimpleXML
Security Tutorial
  • Learn PHP Security
  • Learn HTTP Authentication
  • Learn PHPSecureSite
Framework Tutorial
  • Learn CodeIgniter
  • Learn Joomla
  • Learn Smarty
  • Learn Zend Framework
Template Tutorial
  • Learn Joomla Template
  • Learn WordPress Template
API Tutorial
  • Learn Facebook
JS Framework Tutorial
  • Learn MooTools
  • Learn JQuery
AJAX Tutorial
  • Learn AJAX in 10 Minutes
  • Learn AJAX Client Side
  • Learn AJAX PHP
  • Learn AJAX Remote Server
  • Learn AJAX Repetitive
  • Learn AJAX MySQL
  • Learn AJAX Grid
Web Services Tutorial
  • Learn Web Services NuSOAP
  • Learn Web Services WSDL
  • Learn Web Services WSDL Array
  • Learn Web Services .NET Grid
  • Learn Web Services WDDX
Package Post
  • Joomla Intro
  • Joomla Component
  • Joomla Module
  • Joomla MVC
  • Joomla MVC Backend
  • PostNuke Intro
  • Zend Framework Intro
  • Zend Framework Action
  • Zend Framework Database
  • Zend Framework Registry
  • Zend Framework Config
  • Zend Framework Login
  • Zend Framework Session
  • PHP Array Tips
  • PHP File Tips
  • PHP Email
  • PHP Ms Excel
  • PHP Pattern
  • PHP SMS
  • Flash Database
  • PHP Multitier
  • jQuery Introduction
  • jQuery Selectors
  • Portable Web Server
  • Web Mobile Intro
  • Drupal Installation
  • Drupal Configuration