Skip to content

Add and extra field to Jcomments

Let’s add two additional fields in the form of comments: Town (City) and AcceptTerms (I agree with the rules). the user will need to check.

Adding new fields to the table jos_jcomments

Code:

ALTER TABLE jos_jcomments ADD COLUMN `town` varchar ( 255 ) ; and


Code:

ALTER TABLE jos_jcomments ADD COLUMN `acceptterms` tinyint (1) DEFAULT 0;


Jcomments.class.php open the file and add the data fields in the class JCommentsDB, for example after the following lines:

Code:

var $editor = '' ;


we would get like this:

Code:

var $editor ='';
var $town ='';
var $acceptterms ='';



Open the file jcomments.ajax.php and after the lines:

Code:

$comment -> userid = $my -> id ? $my -> id : 0 ;


add 2 more:

Code:

$comment -> town = isset( $values ['town' ] ) ? $values ['town' ] : '' ;
$comment -> acceptterms = isset($values ['acceptterms'] ) ? $values ['acceptterms']:0 ;



Open the file / tpl / default / tpl_form.php and before the lines:

Code:

<p><textarea id= "comments-form-comment" name= "comment" cols= "65" rows= "8" tabindex= "5" ></textarea></p>


We add our new fields:

Code:

<p> <input type= "text" name= "town" value= "" id= "comments-form-town" />
<label for = "comments-form-town" >Town</label> </ p>

<p><input type= “checkbox” name= “acceptterms” value= “1” id= “comments-form-acceptterms” />
<label for = “comments-form-acceptterms” >Accept Terms of Use</label> /p>


Open the file jcomments.php, we find in it the line:

Code:

$query = "SELECT c.id, c.object_id, c.object_group, c.userid, c.name, c.username, c.title, c.comment"


and replace it with:

Code:


$query = "SELECT c.id, c.object_id, c.object_group, c.userid, c.name, c.username, c.title, c.comment, c.town, c.acceptterms"


This way, we add a sample of information on these fields from the database.

Now open the template file: / tpl / default / tpl_comment.php and admit after lines:

Code:

<span class = "comment-date" ><?php echo date ( 'Ymd H:i' , $comment -> datetime ) ; ?></span>



add the the following:

Code:

<span class = "comment-town" ><?php echo $comment -> town ; ?></span>
<span class = "comment-accept" ><?php echo $comment -> acceptterms ? 'Accepted' : 'Not accepted' ; ?></span>


You are now done go and see if it works.
Note if it does not work first time round check all your code again step by step check for spaces that should not be there ect

After this add the field to the admin list:

Open admin.jcomments.html.php

Find this lines

<?php
if ($row->email != ”) {
?>
<tr valign=”top” align=”left”>
<td><?php echo JText::_(‘A_COMMENT_EMAIL’); ?></td>
<td><input type=”text” size=”35″ name=”email” value=”<?php echo $row->email; ?>” /></td>
</tr>

and add this lines before them:

<tr valign=”top” align=”left”>
<td><?php echo JText::_(‘A_COMMENT_TELEPHONE’); ?></td>
<td><input type=”text” size=”35″ name=”email” value=”<?php echo $row->telephone; ?>” /></td>
</tr>

That’s it.

The original post is from:

http://www.joomlapro.co.uk/forum/components/add-and-extra-field-to-jcomments.html

Published inCoding

4 Comments

  1. elva

    Thank you for your great tutor, but I still have some problem in jcomment.
    how to add a phone field in jcomment but the phone number doesn’t pos in the comment place (only admin can see the phone number from backend area), could you tell me how?

    Thank you

  2. free tire

    Howdy just wanted to give you a brief heads up and let you know a few of the pictures aren’t loading properly.
    I’m not sure why but I think its a linking issue.

    I’ve tried it in two different web browsers and both show the
    same results.

Comments are closed.