{"id":206,"date":"2009-09-12T21:08:26","date_gmt":"2009-09-12T19:08:26","guid":{"rendered":"http:\/\/kavdesign.net\/wordpress\/?p=206"},"modified":"2009-10-24T13:30:21","modified_gmt":"2009-10-24T11:30:21","slug":"add-and-extra-field-to-jcomments","status":"publish","type":"post","link":"https:\/\/www.kavdesign.net\/blog\/coding\/add-and-extra-field-to-jcomments\/","title":{"rendered":"Add and extra field to Jcomments"},"content":{"rendered":"<p>Let&#8217;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.<!--more--><\/p>\n<p><strong>Adding new fields to the table jos_jcomments <\/strong><\/p>\n<table border=\"0\" cellspacing=\"1\" cellpadding=\"3\" width=\"90%\" align=\"center\" summary=\"fireboard\">\n<tbody>\n<tr>\n<td><strong>Code: <\/strong><\/td>\n<\/tr>\n<tr>\n<td>\n<hr \/>\n<p><code>ALTER TABLE  jos_jcomments ADD COLUMN `town`  varchar ( 255 ) ;   and<\/code><\/p>\n<hr \/>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table border=\"0\" cellspacing=\"1\" cellpadding=\"3\" width=\"90%\" align=\"center\" summary=\"fireboard\">\n<tbody>\n<tr>\n<td><strong>Code: <\/strong><\/td>\n<\/tr>\n<tr>\n<td>\n<hr \/>\n<p><code>ALTER TABLE jos_jcomments ADD COLUMN `acceptterms` tinyint (1) DEFAULT 0; <\/code><\/p>\n<hr \/>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Jcomments.class.php open the file and add the data fields in the class JCommentsDB, for example after the following lines:<\/p>\n<table border=\"0\" cellspacing=\"1\" cellpadding=\"3\" width=\"90%\" align=\"center\" summary=\"fireboard\">\n<tbody>\n<tr>\n<td><strong>Code: <\/strong><\/td>\n<\/tr>\n<tr>\n<td>\n<hr \/>\n<p><code> var $editor  = '' ; <\/code><\/p>\n<hr \/>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>we would get like this:<\/strong><\/p>\n<table border=\"0\" cellspacing=\"1\" cellpadding=\"3\" width=\"90%\" align=\"center\" summary=\"fireboard\">\n<tbody>\n<tr>\n<td><strong>Code: <\/strong><\/td>\n<\/tr>\n<tr>\n<td>\n<hr \/>\n<p><code>var $editor ='';<br \/>\nvar $town ='';<br \/>\nvar $acceptterms =''; <\/code><\/p>\n<hr \/>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong><br \/>\nOpen the file jcomments.ajax.php and after the lines: <\/strong><\/p>\n<table border=\"0\" cellspacing=\"1\" cellpadding=\"3\" width=\"90%\" align=\"center\" summary=\"fireboard\">\n<tbody>\n<tr>\n<td><strong>Code: <\/strong><\/td>\n<\/tr>\n<tr>\n<td>\n<hr \/>\n<p><code> $comment -&gt; userid  = $my -&gt; id  ? $my -&gt; id  : 0 ; <\/code><\/p>\n<hr \/>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>add 2 more:<\/p>\n<table border=\"0\" cellspacing=\"1\" cellpadding=\"3\" width=\"90%\" align=\"center\" summary=\"fireboard\">\n<tbody>\n<tr>\n<td><strong>Code: <\/strong><\/td>\n<\/tr>\n<tr>\n<td>\n<hr \/>\n<p><code> $comment -&gt; town  = isset( $values ['town' ] )  ? $values ['town' ]  : '' ;<br \/>\n$comment -&gt; acceptterms  = isset($values ['acceptterms'] ) ? $values ['acceptterms']:0 ; <\/code><\/p>\n<hr \/>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong><br \/>\nOpen the file \/ tpl \/ default \/ tpl_form.php and before the lines:<\/strong><\/p>\n<table border=\"0\" cellspacing=\"1\" cellpadding=\"3\" width=\"90%\" align=\"center\" summary=\"fireboard\">\n<tbody>\n<tr>\n<td><strong>Code: <\/strong><\/td>\n<\/tr>\n<tr>\n<td>\n<hr \/>\n<p><code> &lt;p&gt;&lt;textarea id= \"comments-form-comment\" name= \"comment\" cols= \"65\" rows= \"8\" tabindex= \"5\" &gt;&lt;\/textarea&gt;&lt;\/p&gt; <\/code><\/p>\n<hr \/>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>We add our new fields: <\/strong><\/p>\n<table border=\"0\" cellspacing=\"1\" cellpadding=\"3\" width=\"90%\" align=\"center\" summary=\"fireboard\">\n<tbody>\n<tr>\n<td><strong>Code: <\/strong><\/td>\n<\/tr>\n<tr>\n<td>\n<hr \/>\n<p><code>&lt;p&gt; &lt;input type= \"text\"  name= \"town\"  value= \"\"  id= \"comments-form-town\"  \/&gt;<br \/>\n&lt;label for = \"comments-form-town\" &gt;Town&lt;\/label&gt; &lt;\/ p&gt;<\/code><\/p>\n<p>&lt;p&gt;&lt;input type= &#8220;checkbox&#8221;  name= &#8220;acceptterms&#8221;  value= &#8220;1&#8221;  id= &#8220;comments-form-acceptterms&#8221;  \/&gt;<br \/>\n&lt;label for = &#8220;comments-form-acceptterms&#8221; &gt;Accept Terms of Use&lt;\/label&gt; \/p&gt;<\/p>\n<hr \/>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Open the file jcomments.php, we find in it the line: <\/strong><\/p>\n<table border=\"0\" cellspacing=\"1\" cellpadding=\"3\" width=\"90%\" align=\"center\" summary=\"fireboard\">\n<tbody>\n<tr>\n<td><strong>Code: <\/strong><\/td>\n<\/tr>\n<tr>\n<td>\n<hr \/>\n<p><code> $query  = \"SELECT c.id, c.object_id, c.object_group, c.userid, c.name, c.username, c.title, c.comment\" <\/code><\/p>\n<hr \/>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>and replace it with: <\/strong><\/p>\n<table border=\"0\" cellspacing=\"1\" cellpadding=\"3\" width=\"90%\" align=\"center\" summary=\"fireboard\">\n<tbody>\n<tr>\n<td><strong>Code: <\/strong><\/td>\n<\/tr>\n<tr>\n<td>\n<hr \/>\n<p><code><br \/>\n$query  = \"SELECT c.id, c.object_id, c.object_group, c.userid, c.name, c.username, c.title, c.comment, c.town, c.acceptterms\"<\/code><\/p>\n<hr \/>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>This way, we add a sample of information on these fields from the database.<\/strong><\/p>\n<p><strong>Now open the template file: \/ tpl \/ default \/ tpl_comment.php and admit after lines: <\/strong><\/p>\n<table border=\"0\" cellspacing=\"1\" cellpadding=\"3\" width=\"90%\" align=\"center\" summary=\"fireboard\">\n<tbody>\n<tr>\n<td><strong>Code: <\/strong><\/td>\n<\/tr>\n<tr>\n<td>\n<hr \/>\n<p><code> &lt;span class = \"comment-date\" &gt;&lt;?php echo date ( 'Ymd H:i' , $comment -&gt; datetime ) ; ?&gt;&lt;\/span&gt; <\/code><\/p>\n<hr \/>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong><br \/>\nadd the the following: <\/strong><\/p>\n<table border=\"0\" cellspacing=\"1\" cellpadding=\"3\" width=\"90%\" align=\"center\" summary=\"fireboard\">\n<tbody>\n<tr>\n<td><strong>Code: <\/strong><\/td>\n<\/tr>\n<tr>\n<td>\n<hr \/>\n<p><code>&lt;span class = \"comment-town\" &gt;&lt;?php echo $comment -&gt; town ; ?&gt;&lt;\/span&gt;<br \/>\n&lt;span class = \"comment-accept\" &gt;&lt;?php echo $comment -&gt; acceptterms ? 'Accepted' : 'Not accepted' ; ?&gt;&lt;\/span&gt; <\/code><\/p>\n<hr \/>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>You are now done go and see if it works.<br \/>\nNote 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<\/p>\n<p>After this add the field to the admin list:<\/p>\n<p>Open admin.jcomments.html.php<\/p>\n<p>Find this lines<\/p>\n<p>&lt;?php<br \/>\nif ($row-&gt;email != &#8221;) {<br \/>\n?&gt;<br \/>\n&lt;tr valign=&#8221;top&#8221; align=&#8221;left&#8221;&gt;<br \/>\n&lt;td&gt;&lt;?php echo JText::_(&#8216;A_COMMENT_EMAIL&#8217;); ?&gt;&lt;\/td&gt;<br \/>\n&lt;td&gt;&lt;input type=&#8221;text&#8221; size=&#8221;35&#8243; name=&#8221;email&#8221; value=&#8221;&lt;?php echo $row-&gt;email; ?&gt;&#8221; \/&gt;&lt;\/td&gt;<br \/>\n&lt;\/tr&gt;<\/p>\n<p>and add this lines before them:<\/p>\n<p>&lt;tr valign=&#8221;top&#8221; align=&#8221;left&#8221;&gt;<br \/>\n&lt;td&gt;&lt;?php echo JText::_(&#8216;A_COMMENT_TELEPHONE&#8217;); ?&gt;&lt;\/td&gt;<br \/>\n&lt;td&gt;&lt;input type=&#8221;text&#8221; size=&#8221;35&#8243; name=&#8221;email&#8221; value=&#8221;&lt;?php echo $row-&gt;telephone; ?&gt;&#8221; \/&gt;&lt;\/td&gt;<br \/>\n&lt;\/tr&gt;<\/p>\n<p>That&#8217;s it.<\/p>\n<p>The original post is from:<\/p>\n<p>http:\/\/www.joomlapro.co.uk\/forum\/components\/add-and-extra-field-to-jcomments.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[9],"tags":[],"class_list":["post-206","post","type-post","status-publish","format-standard","hentry","category-coding","entry"],"_links":{"self":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/comments?post=206"}],"version-history":[{"count":2,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/206\/revisions"}],"predecessor-version":[{"id":212,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/206\/revisions\/212"}],"wp:attachment":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/media?parent=206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/categories?post=206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/tags?post=206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}