Jump to content

Add Comments


Guest

Recommended Posts

Can someone please help me with the following code? The problem is the add review form still appears below the thank you text (i.e. after they have submitted a review), I do not know how to get rid off it once the form has been submitted. Any help would be greatly appreciated. This will be a free mod shortly.

addcomment.tpl:

<!-- BEGIN: addcomment -->

<div class="boxContent"> 

<span class="txtContentTitle">{LANG_ADD_COMMENT_TITLE}</span>





<!-- BEGIN: no_error -->

<p>{LANG_ADD_COMMENT_THANKYOU}</p>

<!-- END: no_error -->



<!-- BEGIN: error -->

<p class="txtError">{VAL_ERROR}</p>



<p></P>

<!-- END: error -->



<form action="{FORM_METHOD}" target="_self" method="post">

<input type="hidden" name="act" value="addcomment">

<input type="hidden" name="product_name" value="{TXT_PRODUCT_ID}">





<table  border="0" cellspacing="0" cellpadding="3" width="100%">



<tr align="left">

<td colspan="2"><strong>{LANG_PRODUCT_TITLE}</strong></td>

</tr>

<tr align="left">

<td colspan="2">{TXT_PRODUCT_NAME}







</td>

</tr>



<tr align="left">

<td colspan="2"><strong>{LANG_CUSTOMER_NAME}</strong></td>

</tr>

<tr align="left">

<td colspan="2"><input type="text" name="customer_name" value="{TXT_FIRSTNAME} {TXT_LASTNAME}"></td>

</tr>







<tr align="left">

  <td colspan="2"><strong>{LANG_RATING}</strong><br>{LANG_SELECT_RATING}</td>

  </td></tr><tr>

  <td align="right" colspan="2">

 <table width="300" border="0" cellpadding="2" cellspacing="2">

    <tr>

      <td>1</td>

      <td>2</td>

      <td>3</td>

      <td>4</td>

      <td>5</td>

      <td>6</td>

      <td>7</td>

      <td>8</td>

      <td>9</td>

      <td>10</td>

    </tr>

    <tr>

      <td><input name="rating" type="radio" value="1"></td>

      <td><input name="rating" type="radio" value="2"></td>

      <td><input name="rating" type="radio" value="3"></td>

      <td><input name="rating" type="radio" value="4"></td>

      <td><input name="rating"type="radio" value="5"></td>

      <td><input name="rating"type="radio" value="6"></td>

      <td><input name="rating"type="radio" value="7"></td>

      <td><input name="rating"type="radio" value="8"></td>

      <td><input name="rating"type="radio" value="9"></td>

      <td><input name="rating" type="radio" value="10"></td>

    </tr>

  </table>

</form></td></tr>



<tr align="left">



<td colspan="2"><strong>{TXT_COMMENT}</strong></td>

</tr>



<tr>

<td align="right" colspan="2"><textarea name="comment" cols="40" rows="5" id="comment"></textarea></td>

</tr>







<tr>



<td>&nbsp;</td>

<td><input name="submit" type="submit" value="{TXT_SUBMIT}" class="submit" /></td>

</tr>



</table>

</form>





</div>

<!-- END: addcomment -->




addcomment.inc.php




<?php

/*

+--------------------------------------------------------------------------

|	profile.inc.php

|   ========================================

|	Customers Profile

+--------------------------------------------------------------------------

*/



if(!isset($config)){

	echo "<html>\r\n<head>\r\n<title>Forbidden 403</title>\r\n</head>\r\n<body><h3>Forbidden 403</h3>\r\nThe document you are requesting is forbidden.\r\n</body>\r\n</html>";

	exit;

}



if($ccUserData[0]['customer_id']<=0){ // If customer is not logged in, force them to login before they can make comment.



header("Location: index.php?act=login");



}



if(!$_GET['productId']){



header("Location: index.php"); // If someone is trying to hack by going to index.php?act=addcomment without a product id then redirect it to main index.



}



if(isset($_POST['submit']) && $ccUserData[0]['customer_id']>0){



if (!$_POST['comment'] || !$_POST['rating'] || !$_POST['customer_name']  )  { // check if form has been submitted



	$errorMsg = $lang['front']['addcomment']['complete_all']; // set reminder



	} else {



  // update database

 	 $record['customer_name'] = $db->mySQLSafe($_POST['customer_name']);

 	 $record['product_name'] = $db->mySQLSafe($_POST['product_name']);

 	 $record['rating'] = $db->mySQLSafe($_POST['rating']);

 	 $record['comment'] = $db->mySQLSafe($_POST['comment']);



 	 $updateComment = $db->insert($glob['dbprefix']."CubeCart_customer_comments", $record);





 	 // rebuild customer array



 	 $query = "SELECT * FROM ".$glob['dbprefix']."CubeCart_sessions INNER JOIN ".$glob['dbprefix']."CubeCart_customer ON ".$glob['dbprefix']."CubeCart_sessions.customer_id = ".$glob['dbprefix']."CubeCart_customer.customer_id WHERE sessId = '".$_SESSION['ccUser']."'";



 	 $ccUserData = $db->select($query);



}

}







$addcomment = new XTemplate ("skins/".$config['skinDir']."/styleTemplates/content/addcomment.tpl");





	if(isset($errorMsg)){ // Was there an error message?



  $addcomment->assign("VAL_ERROR",$errorMsg);

  $addcomment->parse("addcomment.error");





	} else { // If there wasn't an error message do this



  if(isset($_POST['submit']) && $ccUserData[0]['customer_id']>0){



  $addcomment->assign("LANG_ADD_COMMENT_THANKYOU",$lang['front']['addcomment']['thank_you']);

  $addcomment->parse("addcomment.no_error");



  }



	}



	$addcomment->assign("LANG_ADD_COMMENT_TITLE",$lang['front']['addcomment']['comment_title']);

	$addcomment->assign("FORM_METHOD",currentPage());



if(isset($errorMsg) || !isset($_POST['submit'])){ // If it has been submitted or there is an error message.



	$query2 = "SELECT name FROM ".$glob['dbprefix']."CubeCart_inventory WHERE productId = '".$_GET['productId']."'";

	$ccProductData = $db->select($query2);





$addcomment->assign("LANG_ADD_COMMENT_TITLE",$lang['front']['addcomment']['comment_title']);



$addcomment->assign("TXT_FIRSTNAME",$ccUserData[0]['firstName']);

$addcomment->assign("TXT_LASTNAME",$ccUserData[0]['lastName']);

$addcomment->assign("TXT_PRODUCT_NAME",$ccProductData[0]['name']);

$addcomment->assign("TXT_PRODUCT_ID",$_GET['productId']);



$addcomment->assign("LANG_PRODUCT_TITLE",$lang['front']['addcomment']['product_name']);

$addcomment->assign("LANG_CUSTOMER_NAME",$lang['front']['addcomment']['customer_name']);

$addcomment->assign("LANG_SELECT_RATING",$lang['front']['addcomment']['select_rating']);

$addcomment->assign("LANG_RATING",$lang['front']['addcomment']['rating']);

$addcomment->assign("LANG_COMMENT",$lang['front']['addcomment']['comment']);



$addcomment->assign("TXT_SUBMIT",$lang['front']['addcomment']['add_comment']);



$addcomment->assign("CURRENT_URL",str_replace(array("&amp;add=".$_GET['add'],"&amp;quan=".$_GET['quan']),"",currentPage()));

}



$addcomment->parse("addcomment");

$page_content = $addcomment->text("addcomment");

?>

Link to comment
Share on other sites

I'm still not familiar with CC 3 or how it's been coded, but after a quick look through your mod, I'm guessing that what you need to do is put your form code in between some curly braces with an if statement like so:

if(!$_POST['submit']) {



ALL YOUR FORM CODE IN HERE



}

Link to comment
Share on other sites

Your not alone...

Could you add the if statement to the php file, where the tpl file is included?

if(!$_POST['submit']) {

$addcomment = new XTemplate ("skins/".$config['skinDir']."/styleTemplates/content/addcomment.tpl");

}

I have no idea if that is right or not though, because I really have no idea what that line is actually doing :P It's just the only line that contains the tpl file...

Link to comment
Share on other sites

Guest GnomeyNewt

There is template switching within the template itself that I have yet to figure out myself. I just reached that block with my mod yesterday and stopped so didn't have a change to look into it further. To keep it consistent you shouldn't add any php code to the template files.

I see code like this in the tpl files:

      <!-- BEGIN: cart_false -->

      <p>{LANG_CART_EMPTY}</p>

      <!-- END: cart_false -->

So we just need to figure out how to active/deactivate it and create our own set of those and it should work nicely. I'll have time tonight to look into it but if somebody already know thats would be nice too!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...