You are here:  » adding extra fields to review


adding extra fields to review

Submitted by Millssy on Sat, 2012-03-03 13:49 in

Hi again!

I have been trying to do somthing similar to this thread over on the forum for the standalon PT
http://www.pricetapestry.com/node/2283

I have added the extra fields etc in the files as shown in the other thread and it works if i look at my PT instilation not through wordpress.

But i cant seem to get it to work in wordpress.

Thanks in advance for your help.

Submitted by support on Sun, 2012-03-04 13:33

Hi Millssy,

Here's the equivalent changes within the plugin. Firstly, to generate the serialized array containing each field instead of the single comments field, look for the following code at line 500 of pto.php:

      $sql = "INSERT INTO `".$pto_config_databaseTablePrefix."reviews` SET created='".time()."',approved='0',product_name='".$wpdb->escape($pto_product)."',rating='".$wpdb->escape($_POST["rating"])."',comments='".$wpdb->escape(stripslashes(trim($_POST["comments"])))."'";

...and REPLACE with:

    $comments = array();
    foreach($_POST as $k => $v)
    {
      if (substr($k,0,9)=="comments_")
      {
        $k = substr($k,9);
        $comments[$k] = stripslashes($v);
      }
    }
    $_POST["comments"] = serialize($comments);
    $sql = "INSERT INTO `".$pto_config_databaseTablePrefix."reviews` SET created='".time()."',approved='0',product_name='".$wpdb->escape($pto_product)."',rating='".$wpdb->escape($_POST["rating"])."',comments='".$wpdb->escape($_POST["comments"])."'";

Next, in pto_product.php, change the name of the comments field to comments_comments, and add any additional fields as comments_custom1, comments_custom2 etc. Look for the following code at line 228:

$form = str_replace("%COMMENTS%","<textarea name='comments' rows='4' width='100%'></textarea><br /><input type='submit' name='submit' value='".$pto_html_reviews_submit."' /></textarea>",$form);

..and REPLACE with:

$form = str_replace("%COMMENTS%","<textarea name='comments' rows='4' width='100%'></textarea><br />",$form);
$form .= "Custom Field 1:<br /><input type='text' name='comments_custom1' /><br />";
$form .= "Custom Field 2:<br /><input type='text' name='comments_custom2' /><br />";
$form .= "<input type='submit' name='submit' value='".$pto_html_reviews_submit."' />";

Finally, where each review is displayed the comments field needs to be unserialized and each field displayed in turn. Look for the following code at line 210:

      $each = str_replace("%COMMENTS%",$review->comments,$each);

....and REPLACE with:

      $comments = unserialize($review->comments);
      $commentsHTML = "";
      $commentsHTML .= $comments["comments"];
      $commentsHTML .= "<br />Custom Field 1: ".$comments["custom1"];
      $commentsHTML .= "<br />Custom Field 2: ".$comments["custom2"];
      $each = str_replace("%COMMENTS%",$commentsHTML,$each);

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Millssy on Thu, 2012-03-08 17:38

Hi,

I have made the changes but it doesnt seem to be parsing any data!

Any ideas?

Submitted by support on Thu, 2012-03-08 18:19

Hi Millssy,

If you'd like to email me your modified files I'll check them out and run it over on my test server for you...

Cheers,
David.
--
PriceTapestry.com