/    Sign up×
Community /Pin to ProfileBookmark

Pass hidden field value

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>[/CODE]

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’]);

}
}
}[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @silviacta spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...