You are here:  » Adding new fields in comment area

Support Forum



Adding new fields in comment area

Submitted by Bakalinge on Thu, 2013-01-03 22:45 in

Hello David,

Since a few months, there is a big debate in France about buying guides and other comparison price websites, most of them are suspected to manipulate users posts/comments (what a news !!)...So, whatever, consurmer's associations recently asked comparison price websites to store some data concerning comment posters : name (or pseudo), email, which both will be given by the user himself, but also comment's date and user's IP (which are hidden fields).

Could you please explain how to integrate this fields in the whole process (database, front end and moderation in admin back end) ?

Thank you very much for your help !

Bak

Submitted by support on Fri, 2013-01-04 08:32

Hello Bak,

Sure - have a look at this post which describes how to add arbitrary additional fields to the reviews data which will give you the basics.

In addition to user entered fields you could capture the IP address and date/time by using the following alternative to the first replacement:

    $comments = array();
    $comments["comments_ip"] = $_SERVER["REMOTE_ADDR"];
    $comments["comments_datetime"] = date("Y-m-d H:i:s");
    foreach($_POST as $k => $v)
    {
      if (substr($k,0,9)=="comments_")
      {
        $k = substr($k,9);
        $comments[$k] = stripslashes($v);
      }
    }
    $_POST["comments"] = serialize($comments);

Of course you don't need to display the IP address (comments_ip) and date/time (comments_datetime), but they will be available in the database if required...

Cheers,
David.
--
PriceTapestry.com

Submitted by Bakalinge on Sun, 2013-01-06 13:36

Hi David,

I answered by email to this, unfortunately the given code is not working for me...

Thanks

Bak

Submitted by Bakalinge on Mon, 2013-01-07 10:46

Hi David,

Still searching why it's working for you and not for me ;)

I have a question : reviews are integrated to my product page, and I used the trick in node 4839...

Should I update the new form handling code from reviews.php to products.php ?

Thanks !

Bak

Submitted by support on Mon, 2013-01-07 10:50

Hello Bak,

Ah yes that would explain things! I did actually reply just a few minutes a go with some debug code but that's probably unnecessary now - if you're not sure how to copy the new handling code into products.php forward that file to me and I'll copy it across for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by Bakalinge on Mon, 2013-01-07 11:11

Ok, now data are stored in the database, but they don't show up in review section (if I use the files you just sent).
With my version, data looks like this in the page :

"a:9:{s:2:\"ip\";s:13:\"88.163.21.181\";s:8:\"datetime\";s:19:\"2013-01-07 12:03:21\";s:8:\"comments\";s:6:\"vsdvdv\";s:3:\"nom\";s:5:\"dsvsd\";s:5:\"ville\";s:4:\"svds\";s:4:\"moto\";s:5:\"sdvsd\";s:4:\"pour\";s:5:\"sdvsd\";s:6:\"contre\";s:5:\"sdvsd\";s:10:\"conclusion\";s:6:\"vdsvsd\";}"

I'm a little confused, I just sent you the 3 files

Thanks David !

Submitted by support on Tue, 2013-01-08 14:47

Thanks for the files - and your up and running reply!

For the benefit of other users, this was down to a magic quotes handling anomaly and resolved using this mod.

Cheers,
David.
--
PriceTapestry.com