Skip to content

Commit

Permalink
use application/x-www-form-urlencoded to avoid changes in PHP code
Browse files Browse the repository at this point in the history
  • Loading branch information
leemyongpakvn committed Oct 26, 2023
1 parent c72a8c5 commit 1a6a64a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
4 changes: 1 addition & 3 deletions controllers/front/ReportComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public function display()
return false;
}

$content = trim(file_get_contents('php://input'));
$decoded = json_decode($content, true);
$id_product_comment = (int) $decoded['id_product_comment'];
$id_product_comment = (int) Tools::getValue('id_product_comment');

/** @var EntityManagerInterface $entityManager */
$entityManager = $this->container->get('doctrine.orm.entity_manager');
Expand Down
6 changes: 2 additions & 4 deletions controllers/front/UpdateCommentUsefulness.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ public function display()
return false;
}

$content = trim(file_get_contents('php://input'));
$decoded = json_decode($content, true);
$id_product_comment = (int) $decoded['id_product_comment'];
$usefulness = (bool) $decoded['usefulness'];
$id_product_comment = (int) Tools::getValue('id_product_comment');
$usefulness = (bool) Tools::getValue('usefulness');

/** @var EntityManagerInterface $entityManager */
$entityManager = $this->container->get('doctrine.orm.entity_manager');
Expand Down
10 changes: 5 additions & 5 deletions views/js/list-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ jQuery(document).ready(function () {
const response = await fetch(updateCommentUsefulnessUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
},
body: JSON.stringify({id_product_comment: commentId, usefulness: usefulness}),
body: "id_product_comment=" + commentId + "&usefulness=" + usefulness,
});

if (response.status === 200) {
Expand Down Expand Up @@ -222,9 +222,9 @@ jQuery(document).ready(function () {
const response = await fetch(reportCommentUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({id_product_comment: commentId}),
"Content-Type": "application/x-www-form-urlencoded",
},
body: "id_product_comment=" + commentId,
});

if (response.status === 200) {
Expand Down

0 comments on commit 1a6a64a

Please sign in to comment.