Passing scanned QR content to PHP












0















I have a QR code scanner that already works using Instascan and Vue.js libraries. Now what I want to do is to automatically post the scanned content to a php file and redirect to that php file after scanning, but I can't seem to pass the value. Here is my HTML code:



    <div class="form-group" id="app">
<label v-for="scan in scans" class="disptext" style="font-size: 30px; top: 73%; left: 45%;">Welcome, </label>
<input v-for="scan in scans" :key="scan.date" :title="scan.content" class="form-control" id="qr_user" name="qr_user" placeholder="Scan User QR Code" :value="scan.content" style="width: auto; font-size: 30px; left: 37%; text-align: center; position: absolute; top: 80%; border: 0; background: transparent;">
<input type="hidden" name="qr" id="qr" :key="scan.date" />
</div>


I tried posting it through my js file like this:



    mounted: function () {
var self = this;
self.scanner = new Instascan.Scanner({ video: document.getElementById('preview'), scanPeriod: 5 });
self.scanner.addListener('scan', function (content, image) {
self.scans.unshift({ date: +(Date.now()), content: content });
$.post("scanquery.php", {qr: content});
window.location.assign("scanquery.php");
});


But php executes first so "qr" is always undefined. How can I do this?



Edit



Here is the php code, I just posted it by calling the "qr":



    $user = $_POST['qr'];
if(!empty($user)){
echo $user;
}









share|improve this question

























  • Can we see your php code as well?

    – Jim B.
    Nov 24 '18 at 19:10











  • Already edited it, Sir.

    – Gelo Manalo
    Nov 24 '18 at 19:16











  • You can output debug messages in PHP: php.net/manual/en/debugger.php . If $_POST is not set to anything, I think you have a mismatch in payload formats.

    – Jim B.
    Nov 24 '18 at 19:33











  • I tried to use var_dump() and print_r() to verify the content of the $_POST and all returned 0 or null.

    – Gelo Manalo
    Nov 24 '18 at 19:42
















0















I have a QR code scanner that already works using Instascan and Vue.js libraries. Now what I want to do is to automatically post the scanned content to a php file and redirect to that php file after scanning, but I can't seem to pass the value. Here is my HTML code:



    <div class="form-group" id="app">
<label v-for="scan in scans" class="disptext" style="font-size: 30px; top: 73%; left: 45%;">Welcome, </label>
<input v-for="scan in scans" :key="scan.date" :title="scan.content" class="form-control" id="qr_user" name="qr_user" placeholder="Scan User QR Code" :value="scan.content" style="width: auto; font-size: 30px; left: 37%; text-align: center; position: absolute; top: 80%; border: 0; background: transparent;">
<input type="hidden" name="qr" id="qr" :key="scan.date" />
</div>


I tried posting it through my js file like this:



    mounted: function () {
var self = this;
self.scanner = new Instascan.Scanner({ video: document.getElementById('preview'), scanPeriod: 5 });
self.scanner.addListener('scan', function (content, image) {
self.scans.unshift({ date: +(Date.now()), content: content });
$.post("scanquery.php", {qr: content});
window.location.assign("scanquery.php");
});


But php executes first so "qr" is always undefined. How can I do this?



Edit



Here is the php code, I just posted it by calling the "qr":



    $user = $_POST['qr'];
if(!empty($user)){
echo $user;
}









share|improve this question

























  • Can we see your php code as well?

    – Jim B.
    Nov 24 '18 at 19:10











  • Already edited it, Sir.

    – Gelo Manalo
    Nov 24 '18 at 19:16











  • You can output debug messages in PHP: php.net/manual/en/debugger.php . If $_POST is not set to anything, I think you have a mismatch in payload formats.

    – Jim B.
    Nov 24 '18 at 19:33











  • I tried to use var_dump() and print_r() to verify the content of the $_POST and all returned 0 or null.

    – Gelo Manalo
    Nov 24 '18 at 19:42














0












0








0








I have a QR code scanner that already works using Instascan and Vue.js libraries. Now what I want to do is to automatically post the scanned content to a php file and redirect to that php file after scanning, but I can't seem to pass the value. Here is my HTML code:



    <div class="form-group" id="app">
<label v-for="scan in scans" class="disptext" style="font-size: 30px; top: 73%; left: 45%;">Welcome, </label>
<input v-for="scan in scans" :key="scan.date" :title="scan.content" class="form-control" id="qr_user" name="qr_user" placeholder="Scan User QR Code" :value="scan.content" style="width: auto; font-size: 30px; left: 37%; text-align: center; position: absolute; top: 80%; border: 0; background: transparent;">
<input type="hidden" name="qr" id="qr" :key="scan.date" />
</div>


I tried posting it through my js file like this:



    mounted: function () {
var self = this;
self.scanner = new Instascan.Scanner({ video: document.getElementById('preview'), scanPeriod: 5 });
self.scanner.addListener('scan', function (content, image) {
self.scans.unshift({ date: +(Date.now()), content: content });
$.post("scanquery.php", {qr: content});
window.location.assign("scanquery.php");
});


But php executes first so "qr" is always undefined. How can I do this?



Edit



Here is the php code, I just posted it by calling the "qr":



    $user = $_POST['qr'];
if(!empty($user)){
echo $user;
}









share|improve this question
















I have a QR code scanner that already works using Instascan and Vue.js libraries. Now what I want to do is to automatically post the scanned content to a php file and redirect to that php file after scanning, but I can't seem to pass the value. Here is my HTML code:



    <div class="form-group" id="app">
<label v-for="scan in scans" class="disptext" style="font-size: 30px; top: 73%; left: 45%;">Welcome, </label>
<input v-for="scan in scans" :key="scan.date" :title="scan.content" class="form-control" id="qr_user" name="qr_user" placeholder="Scan User QR Code" :value="scan.content" style="width: auto; font-size: 30px; left: 37%; text-align: center; position: absolute; top: 80%; border: 0; background: transparent;">
<input type="hidden" name="qr" id="qr" :key="scan.date" />
</div>


I tried posting it through my js file like this:



    mounted: function () {
var self = this;
self.scanner = new Instascan.Scanner({ video: document.getElementById('preview'), scanPeriod: 5 });
self.scanner.addListener('scan', function (content, image) {
self.scans.unshift({ date: +(Date.now()), content: content });
$.post("scanquery.php", {qr: content});
window.location.assign("scanquery.php");
});


But php executes first so "qr" is always undefined. How can I do this?



Edit



Here is the php code, I just posted it by calling the "qr":



    $user = $_POST['qr'];
if(!empty($user)){
echo $user;
}






php vue.js qr-code






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 19:14







Gelo Manalo

















asked Nov 24 '18 at 18:36









Gelo ManaloGelo Manalo

183




183













  • Can we see your php code as well?

    – Jim B.
    Nov 24 '18 at 19:10











  • Already edited it, Sir.

    – Gelo Manalo
    Nov 24 '18 at 19:16











  • You can output debug messages in PHP: php.net/manual/en/debugger.php . If $_POST is not set to anything, I think you have a mismatch in payload formats.

    – Jim B.
    Nov 24 '18 at 19:33











  • I tried to use var_dump() and print_r() to verify the content of the $_POST and all returned 0 or null.

    – Gelo Manalo
    Nov 24 '18 at 19:42



















  • Can we see your php code as well?

    – Jim B.
    Nov 24 '18 at 19:10











  • Already edited it, Sir.

    – Gelo Manalo
    Nov 24 '18 at 19:16











  • You can output debug messages in PHP: php.net/manual/en/debugger.php . If $_POST is not set to anything, I think you have a mismatch in payload formats.

    – Jim B.
    Nov 24 '18 at 19:33











  • I tried to use var_dump() and print_r() to verify the content of the $_POST and all returned 0 or null.

    – Gelo Manalo
    Nov 24 '18 at 19:42

















Can we see your php code as well?

– Jim B.
Nov 24 '18 at 19:10





Can we see your php code as well?

– Jim B.
Nov 24 '18 at 19:10













Already edited it, Sir.

– Gelo Manalo
Nov 24 '18 at 19:16





Already edited it, Sir.

– Gelo Manalo
Nov 24 '18 at 19:16













You can output debug messages in PHP: php.net/manual/en/debugger.php . If $_POST is not set to anything, I think you have a mismatch in payload formats.

– Jim B.
Nov 24 '18 at 19:33





You can output debug messages in PHP: php.net/manual/en/debugger.php . If $_POST is not set to anything, I think you have a mismatch in payload formats.

– Jim B.
Nov 24 '18 at 19:33













I tried to use var_dump() and print_r() to verify the content of the $_POST and all returned 0 or null.

– Gelo Manalo
Nov 24 '18 at 19:42





I tried to use var_dump() and print_r() to verify the content of the $_POST and all returned 0 or null.

– Gelo Manalo
Nov 24 '18 at 19:42












1 Answer
1






active

oldest

votes


















0














You can defer execution of window.location.assign() until after the post completes by using a callback in $.post:



$.post("scanquery.php", {qr: content}, () => {
window.location.assign("scanquery.php");
});


I think you have a mismatch in your payload types. $.post is formatting your object as JSON, and $_POST is not made available for JSON posts.



This source (https://davidwalsh.name/php-json) notes how to process incoming data as JSON:



# Get JSON as a string
$json_str = file_get_contents('php://input');

# Get as an object
$json_obj = json_decode($json_str);


Someone more of an expert on PHP can correct me on this part.






share|improve this answer


























  • It still says undefined. I'm not sure if I am doing this right. Here is my php code: $user = $_POST['qr']; if(!empty($user)){ echo $user; } Am I retrieving it right?

    – Gelo Manalo
    Nov 24 '18 at 19:02













  • Have you validated that content and image are valid before calling $.post?

    – Jim B.
    Nov 24 '18 at 19:09











  • Yes, I have. I displayed the content's value via console.log() and it definitely returns the QR code content.

    – Gelo Manalo
    Nov 24 '18 at 19:10











  • Ok, we need to see your php code. I suspect it has to do with how you're passing the parameters.

    – Jim B.
    Nov 24 '18 at 19:11











  • Can you validate that $_POST is actually set correctly on the PHP side? It's only set for you under certain conditions.

    – Jim B.
    Nov 24 '18 at 19:27











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53461242%2fpassing-scanned-qr-content-to-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You can defer execution of window.location.assign() until after the post completes by using a callback in $.post:



$.post("scanquery.php", {qr: content}, () => {
window.location.assign("scanquery.php");
});


I think you have a mismatch in your payload types. $.post is formatting your object as JSON, and $_POST is not made available for JSON posts.



This source (https://davidwalsh.name/php-json) notes how to process incoming data as JSON:



# Get JSON as a string
$json_str = file_get_contents('php://input');

# Get as an object
$json_obj = json_decode($json_str);


Someone more of an expert on PHP can correct me on this part.






share|improve this answer


























  • It still says undefined. I'm not sure if I am doing this right. Here is my php code: $user = $_POST['qr']; if(!empty($user)){ echo $user; } Am I retrieving it right?

    – Gelo Manalo
    Nov 24 '18 at 19:02













  • Have you validated that content and image are valid before calling $.post?

    – Jim B.
    Nov 24 '18 at 19:09











  • Yes, I have. I displayed the content's value via console.log() and it definitely returns the QR code content.

    – Gelo Manalo
    Nov 24 '18 at 19:10











  • Ok, we need to see your php code. I suspect it has to do with how you're passing the parameters.

    – Jim B.
    Nov 24 '18 at 19:11











  • Can you validate that $_POST is actually set correctly on the PHP side? It's only set for you under certain conditions.

    – Jim B.
    Nov 24 '18 at 19:27
















0














You can defer execution of window.location.assign() until after the post completes by using a callback in $.post:



$.post("scanquery.php", {qr: content}, () => {
window.location.assign("scanquery.php");
});


I think you have a mismatch in your payload types. $.post is formatting your object as JSON, and $_POST is not made available for JSON posts.



This source (https://davidwalsh.name/php-json) notes how to process incoming data as JSON:



# Get JSON as a string
$json_str = file_get_contents('php://input');

# Get as an object
$json_obj = json_decode($json_str);


Someone more of an expert on PHP can correct me on this part.






share|improve this answer


























  • It still says undefined. I'm not sure if I am doing this right. Here is my php code: $user = $_POST['qr']; if(!empty($user)){ echo $user; } Am I retrieving it right?

    – Gelo Manalo
    Nov 24 '18 at 19:02













  • Have you validated that content and image are valid before calling $.post?

    – Jim B.
    Nov 24 '18 at 19:09











  • Yes, I have. I displayed the content's value via console.log() and it definitely returns the QR code content.

    – Gelo Manalo
    Nov 24 '18 at 19:10











  • Ok, we need to see your php code. I suspect it has to do with how you're passing the parameters.

    – Jim B.
    Nov 24 '18 at 19:11











  • Can you validate that $_POST is actually set correctly on the PHP side? It's only set for you under certain conditions.

    – Jim B.
    Nov 24 '18 at 19:27














0












0








0







You can defer execution of window.location.assign() until after the post completes by using a callback in $.post:



$.post("scanquery.php", {qr: content}, () => {
window.location.assign("scanquery.php");
});


I think you have a mismatch in your payload types. $.post is formatting your object as JSON, and $_POST is not made available for JSON posts.



This source (https://davidwalsh.name/php-json) notes how to process incoming data as JSON:



# Get JSON as a string
$json_str = file_get_contents('php://input');

# Get as an object
$json_obj = json_decode($json_str);


Someone more of an expert on PHP can correct me on this part.






share|improve this answer















You can defer execution of window.location.assign() until after the post completes by using a callback in $.post:



$.post("scanquery.php", {qr: content}, () => {
window.location.assign("scanquery.php");
});


I think you have a mismatch in your payload types. $.post is formatting your object as JSON, and $_POST is not made available for JSON posts.



This source (https://davidwalsh.name/php-json) notes how to process incoming data as JSON:



# Get JSON as a string
$json_str = file_get_contents('php://input');

# Get as an object
$json_obj = json_decode($json_str);


Someone more of an expert on PHP can correct me on this part.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 24 '18 at 19:49

























answered Nov 24 '18 at 18:56









Jim B.Jim B.

2,6721929




2,6721929













  • It still says undefined. I'm not sure if I am doing this right. Here is my php code: $user = $_POST['qr']; if(!empty($user)){ echo $user; } Am I retrieving it right?

    – Gelo Manalo
    Nov 24 '18 at 19:02













  • Have you validated that content and image are valid before calling $.post?

    – Jim B.
    Nov 24 '18 at 19:09











  • Yes, I have. I displayed the content's value via console.log() and it definitely returns the QR code content.

    – Gelo Manalo
    Nov 24 '18 at 19:10











  • Ok, we need to see your php code. I suspect it has to do with how you're passing the parameters.

    – Jim B.
    Nov 24 '18 at 19:11











  • Can you validate that $_POST is actually set correctly on the PHP side? It's only set for you under certain conditions.

    – Jim B.
    Nov 24 '18 at 19:27



















  • It still says undefined. I'm not sure if I am doing this right. Here is my php code: $user = $_POST['qr']; if(!empty($user)){ echo $user; } Am I retrieving it right?

    – Gelo Manalo
    Nov 24 '18 at 19:02













  • Have you validated that content and image are valid before calling $.post?

    – Jim B.
    Nov 24 '18 at 19:09











  • Yes, I have. I displayed the content's value via console.log() and it definitely returns the QR code content.

    – Gelo Manalo
    Nov 24 '18 at 19:10











  • Ok, we need to see your php code. I suspect it has to do with how you're passing the parameters.

    – Jim B.
    Nov 24 '18 at 19:11











  • Can you validate that $_POST is actually set correctly on the PHP side? It's only set for you under certain conditions.

    – Jim B.
    Nov 24 '18 at 19:27

















It still says undefined. I'm not sure if I am doing this right. Here is my php code: $user = $_POST['qr']; if(!empty($user)){ echo $user; } Am I retrieving it right?

– Gelo Manalo
Nov 24 '18 at 19:02







It still says undefined. I'm not sure if I am doing this right. Here is my php code: $user = $_POST['qr']; if(!empty($user)){ echo $user; } Am I retrieving it right?

– Gelo Manalo
Nov 24 '18 at 19:02















Have you validated that content and image are valid before calling $.post?

– Jim B.
Nov 24 '18 at 19:09





Have you validated that content and image are valid before calling $.post?

– Jim B.
Nov 24 '18 at 19:09













Yes, I have. I displayed the content's value via console.log() and it definitely returns the QR code content.

– Gelo Manalo
Nov 24 '18 at 19:10





Yes, I have. I displayed the content's value via console.log() and it definitely returns the QR code content.

– Gelo Manalo
Nov 24 '18 at 19:10













Ok, we need to see your php code. I suspect it has to do with how you're passing the parameters.

– Jim B.
Nov 24 '18 at 19:11





Ok, we need to see your php code. I suspect it has to do with how you're passing the parameters.

– Jim B.
Nov 24 '18 at 19:11













Can you validate that $_POST is actually set correctly on the PHP side? It's only set for you under certain conditions.

– Jim B.
Nov 24 '18 at 19:27





Can you validate that $_POST is actually set correctly on the PHP side? It's only set for you under certain conditions.

– Jim B.
Nov 24 '18 at 19:27




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53461242%2fpassing-scanned-qr-content-to-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python