Hi, I am new to PHP so please forgive me for any mistake.
I’m trying to pass a hidden value, the review_id, so I cam delete the review with that id. It delete’s a review if I click the button twice.
Here’s the tpl doc
[CODE]<h2>Customer reviews:</h2>
<ul class=”reviews-list”>
{section name=i loop=$obj->mReviews}
<li>
<p>
Review by <strong>{$obj->mReviews[i].name}</strong> on
{$obj->mReviews[i].created_on|date_format:”%A, %B %e, %Y”}
</p>
<p>{$obj->mReviews[i].review}</p>
<p>Rating: [{$obj->mReviews[i].rating} of 5]</p>
{* Show Delete Review button for admin *}
{if $obj->mShowDeleteReviewButton}
<form method=”post” action=”{$obj->mLinkToProduct}”>
<p>
<input type=”hidden” name=”review_id” value=”{$obj->mReviews[i].review_id}” />
<input type=”submit” name=”delete_review” value=”Delete Review” />
</p>
</form>
{/if}
<p>{$obj->mReviews[i].review_id}</p>
</li>
{/section}
</ul>
And this is the php doc
[code=php]class Reviews
{
public $mProductId;
public $mReviews;
public $mTotalReviews;
public $mReviewerName;
public $mEnableAddProductReviewForm = false;
public $mLinkToProduct;
public $mShowDeleteReviewButton;
private $_mReviewId;
public function __construct()
{
if (isset($_GET[‘ProductId’]))
$this->mProductId = (int)$_GET[‘ProductId’];
else
trigger_error(‘ProductId not set’, E_USER_ERROR);
$this->mLinkToProduct = Link::ToProduct($this->mProductId);
// Afiseaza butonul de stergere Review pentru administrator
if (!(isset($_SESSION[‘admin_logged’])) || $_SESSION[‘admin_logged’] != true)
$this->mShowDeleteReviewButton = false;
else
$this->mShowDeleteReviewButton = true;
}
public function init()
{
// If visitor is logged in …
if (Customer::IsAuthenticated())
{
// Check if visitor is adding a review
if (isset($_POST[‘AddProductReview’]))
Catalog::CreateProductReview(Customer::GetCurrentCustomerId(),
$this->mProductId, $_POST[‘review’], $_POST[‘rating’]);
// Display “add review” form because visitor si registred
$this->mEnableAddProductReviewForm = true;
// Get visitor’s (reviewer’s) name
$customer_data = Customer::Get();
$this->mReviewerName = $customer_data[‘name’];
}
// Get reviews for this product
$this->mReviews = Catalog::GetProductReviews($this->mProductId);
// Get the number of the reviews
$this->mTotalReviews = count($this->mReviews);
if (isset($_POST[‘delete_review’]))
{
Catalog::DeleteReview((int)$_POST[‘review_id’]);
}
}
}