Author Topic: extra fields in comment form  (Read 6712 times)

0 Members and 1 Guest are viewing this topic.

Offline sukholee

  • Newbie
  • *
  • Posts: 26
    • View Profile
extra fields in comment form
« on: August 03, 2002, 08:07:37 PM »
Is there any way of adding additional fields under the comment form. At the moment there are three fields; name, title, and comment....

I would like to add a fourth to this form. If any one can help please post a solution.

Thanks.

Offline Alan @ ArtScans

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • http://www.qcs-software.com
extra fields in comment form
« Reply #1 on: August 05, 2002, 12:19:10 AM »
Hi,

Now, before I run off into a long blurb about how to do this, I'm sure I remember something about some Extra Fields functions that appeared not long ago in 4images, but I don't remember anything about them offhand.  I expect they will do what you need, without having to masacre files like I'm about to tell you to do :-)

NOTE: Be sure to take a full backup of any changed files, as what I've written below is just off the top of my head, and I havn't tested it.



(In this example, I'm going to assume that you want the extra field to hold a website URL)

Open up the file comment_form.html in your templates directory, and add the html for the extra field in there.  Call it something like "{lang_comment_website}" and "frm_comment_website" or something.  Also, edit comment_bit.html and add in the extra field here as well.

Next, edit your language files, and add a new entry for "{lang_comment_website}", eg, "$lang['comment_website']="Website URL"" (or whatever you want the extra field to be.)

Next, open up details.php, and browse down to the line that reads ...
Code: [Select]

$comment_text = un_htmlspecialchars(trim($HTTP_POST_VARS['comment_text']));

Duplicate this line, but change the details to match your new field, eg
Code: [Select]

$comment_website = un_htmlspecialchars(trim($HTTP_POST_VARS['frm_comment_website']));

If you wish to check that the field has something useful in it, add a block in the "if (xxx == "")..etc" section a few lines down.

Change the line ...
Code: [Select]

$sql = "INSERT INTO ".COMMENTS_TABLE." (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date) VALUES  $id, ".$user_info 'user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().")";

To read ...
Code: [Select]

$sql = "INSERT INTO ".COMMENTS_TABLE." (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date, comment_website) VALUES  $id, ".$user_info 'user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().", '$comment_website')";


Next, (still in details.php) move down to the Show Comments section.  

Look for any SQL SELECT statements in this block of code, and tack your "comment_website" bit on in the appropriate places.

Next, look for the block that starts
Code: [Select]

$site_template->register_vars(array(

On the bottom of the list of template vars, add something like...
Code: [Select]

"lang_comment_website" => $lang['comment_website'],
"frm_comment_website" => $comment_row[$i]['comment_website']

Remember to add a comma to the line above these 2 (if it doesn't have one), and you may wish to use the format_text() functions as well.

Once you've done all this, you'll need to edit the comments table in the database itself, and add the new field.  Use something like...
Code: [Select]

ALTER TABLE comments ADD comment_website varchar(100) DEFAULT NULL;


I know I've missed stuff above, and I honestly doubt that the code above will work out of the box, so don't just go cutting and pasting it all over the place :), but it's a starting block for you to build on :-)

As I mentioned at the begining of this post, I'm sure Jan introduced somehting that was supposed to make this sort of thing easier, but I can't remember the details off-hand.

Good luck with it.

Thanks,
Alan.
Alan Wagstaff,
Software Development Manager, SDT
QCS Software

Offline sukholee

  • Newbie
  • *
  • Posts: 26
    • View Profile
extra fields in comment form
« Reply #2 on: August 05, 2002, 02:57:53 PM »
Hi Alan,

I just want to thank you for posting such a comprehensive explanation.

It was very easy to follow and works very well.  :D

Thanks a lot

Offline Alan @ ArtScans

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • http://www.qcs-software.com
extra fields in comment form
« Reply #3 on: August 05, 2002, 06:57:14 PM »
Hi,

Your welcome for the long explanation, and I'm suprised it works at all :D

I was writing a mod which did simaler things to your comments one, at the time, so it was all still fresh in my mind :-)

Thanks,
Alan.
Alan Wagstaff,
Software Development Manager, SDT
QCS Software

Offline CEGRAPHIX

  • Pre-Newbie
  • Posts: 7
    • View Profile
Re: extra fields in comment form
« Reply #4 on: July 08, 2005, 08:50:08 PM »
:(

I keep getting this error:

DB Error: Bad SQL Query: INSERT INTO 4images_comments (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date, comment_website) VALUES 198, 1, 'sweet', 'test', 'test', '69.229.38.113', 1120848460, 'http://www.test.com')
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '198, 1, 'sweet', 'test', 'test', '69.229.38.113', 1120848460, '

and I have THIS:

$sql = "INSERT INTO ".COMMENTS_TABLE." (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date, comment_website) VALUES  $id, ".$user_info ['user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().", '$comment_website')";

PUHLEASE help. :(

Offline CEGRAPHIX

  • Pre-Newbie
  • Posts: 7
    • View Profile
Re: extra fields in comment form
« Reply #5 on: July 08, 2005, 09:06:25 PM »
figured it out......the red shows what was missing in the hack above...

instead of:

$sql = "INSERT INTO ".COMMENTS_TABLE." (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date, comment_website) VALUES  ($id, ".$user_info '[user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().", '$comment_website')";


the change should be:

Code: [Select]
$sql = "INSERT INTO ".COMMENTS_TABLE."
              (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date, comment_website)
              VALUES
              ($id, ".$user_info['user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().", '$comment_website')";
     

Offline Vincent

  • 4images Moderator
  • Addicted member
  • *****
  • Posts: 1.195
    • View Profile
    • www.foto-kocher.com
Re: extra fields in comment form
« Reply #6 on: July 19, 2005, 11:17:42 AM »
Hello
on my page i would like to use the comment system to do at the end something like this
http://www.foto-kocher.com/sold2004.php

until know i have the comment system not in use.
is there somebody out there helping me to change it!

sincerly
vincent
Beati pauperi spiritus

4images 1.7 // My Installed Mods