22:32:22

Web Design Studio Ltd
Whiteside Buildings
Office 2
Back St. Annes Rd West
Lytham St. Annes
Lancashire
FY8 1RD

Tel: 01253 721000

The Joomla Community

                 A place for all Joomla People to hang out.

 

 

 

 

 

 

 

 

Add and extra field to Jcomments (1 viewing) (1) Guest
Add and extra field to Jcomments
by Joomla Pro 10 Months, 4 Weeks ago
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
The administrator has disabled public write access. | Report to moderator   Logged Logged  
       
Joomla Web Designers | Joomla Developers | Joomla Training