0

Below is the code.

under the function there is a resultContainer.innerHTML that populates a list of QR codes scanned. How can $_POST the values in PHP so that I can send it in an email format? I tried adding a name within the div (<div **name="qrOutput"**>[${countResults}] - ${qrCodeMessage}</div>) but PHP does not pick it up. Only returns an empty string.

I also tried giving the <div id="qr-reader-results"></div> element a name but because the output is within another div inside this div I also got an empty result.

Thanks a lot for any help.

<!-- start -->
<div id="qr-reader" style="width:500px"></div>
<div id="qr-reader-results"></div>


<div id="root"></div>
<script>
  function docReady(fn) {
    // see if DOM is already available
    if (document.readyState === "complete" ||
      document.readyState === "interactive") {
      // call on next available tick
      setTimeout(fn, 1);
    } else {
      document.addEventListener("DOMContentLoaded", fn);
    }
  }

  docReady(function() {
    var resultContainer = document.getElementById('qr-reader-results');
    var lastResult, countResults = 0;

    function onScanSuccess(qrCodeMessage) {
      if (qrCodeMessage !== lastResult) {
        ++countResults;
        lastResult = qrCodeMessage;
        resultContainer.innerHTML += ***`<div">[${countResults}] - ${qrCodeMessage}</div>`;***
      }
    }

    var html5QrcodeScanner = new Html5QrcodeScanner(
      "qr-reader", {
        fps: 10,
        qrbox: 250
      });
    html5QrcodeScanner.render(onScanSuccess);
  });
</script>
<p id="QRout"></p>
emppeak
  • 119
  • 10
Dave9608
  • 3
  • 1

1 Answers1

0

You can store your results in an other variable when you add it to the DOM.

  1. Declare a variable to store your results
var myResults = [];
  1. When you add the result to the DOM add also the results in array variable
// ...
resultContainer.innerHTML += `<div>[${countResults}] - ${qrCodeMessage}</div>`;
myResults.push({count: countResults, message: qrCodeMessage})
  1. Then you can use myResult var on a POST request
myCustomPostFunction('/yourUrl/', myResult);

The "myCustomPostFunction" will depend on the way you want to send the data

Check this codepen: https://codepen.io/zecka/pen/VwKNpze

Post request like a form submit

If you want to send the data to the current page like a form post, you can find an example here: https://stackoverflow.com/a/133997/2838586

Post request to a rest api

Fetch: POST json data

ZecKa
  • 1,551
  • 11
  • 24