After create table in database, now we build form which visitor will leave comment. This form will be loaded when single posting displayed. We involve session to make this form more advance. When they logged, their name will display at the form.
- Open "hello.html.php" file within joomla/components.
Enter following function:
function showCommentForm($option, $hello_id, $name)
{
?>
<br /><br />
<form action="index.php" method="post">
<table>
<tr>
<td>
<strong>Name: </strong>
</td>
<td>
<input class="text_area" type="text"
name="full_name" id="full_name"
value="<?php echo $name; ?>" />
</td>
</tr>
<tr>
<td>
<strong>Comment:</strong>
</td>
<td>
<textarea class="text_area" cols="20" rows="4"
name="comment_text" id="comment_text"
style="width:500px"></textarea>
</td>
</tr>
</table>
<input type="hidden" name="hello_id"
value="<?php echo $hello_id?>" />
<input type="hidden" name="task"
value="comment" />
<input type="hidden" name="option"
value="<?php echo $option?>" />
<input type="submit" class="button"
id="button" value="Submit" />
</form>
<?php
}
- Open "hello.php" within joomla/components. Enter
following bold code in viewHello():
function viewHello($option)
{
$id = JRequest::getVar('id', 0);
$row =& JTable::getInstance( 'hello', 'Table');
$row->load($id);
if(!$row->published)
{
JError::raiseError( 404, JText::_('Invalid ID Provided'));
}
HTML_hello::viewHello($row, $option);
$user =& JFactory::getUser();
if($user->name)
{
$name = $user->name;
}
else
{
$name = '';
}
HTML_hello::showCommentForm($option, $id, $name);
}
When you access, for example like this http://localhost/Joomla/hello-world/view/2, the form comment loaded.