You are on page 1of 2

8.

22 Input the Comment Data


After making of the comment input form in the previous chapter, now, we are going to make the form is active. Here are the steps to input the comment into database: 1. 2. Open hello.php in myjoomla/components/com_book. In switch part, insert the task for "comment":

01 switch( $task ){ 02 case 'view': 03 04 05 06 07 08 09 10 11 12 13 }


9. We need the addComment() function to input the comment into database:

viewBook($option); break; case 'comment': addComment($option); break; default: showPublishedBook($option); break;

01 function addComment($option) 02 { 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 if($user->id) { $row->user_id = $user->id; } $user =& JFactory::getUser(); $row->comment_date = date ( 'Y-m-d H:i:s' ); $row =& JTable::getInstance( 'comment' , 'Table' ); if (!$row->bind(JRequest::get( 'post' ))) { JError::raiseError(500, $row->getError() ); } global $mainframe;

20 21 22 23 24 25 26 27 28 29 30 }

if(!$row->store()) { JError::raiseError(500, $row->getError() ); } $link = JRoute::_( 'index.php?option='.$option. '&id='.$row->book_id . '&task=view' ); $mainframe->redirect( $link, 'Komentar Anda berhasil diinputkan' );

Now, you can try to write the comment and save it.

Picture 8.28 Message if the comment is succeeded in inputted Previous: 8.21 Make the Comment Form Next: 8.23 Publish the Comment

You might also like