0

I have a test page that displays my POST data. I am trying to view the post that I just submitted but I am unable to see the added payload I added in my form.

HTML:

  <form id="test-form" action="/test/" method="post"> {# pass data to /test/ URL #}
    <div class="test-button-set">
      <button type="button" id="hdfs-test" class="btn btn-default btn-lg selected">HDFS</button>
      <button type="button" id="hive-test" class="btn btn-default btn-lg">HIVE</button>
      <button type="button" id="hdfs-hive-test" class="btn btn-default btn-lg">BOTH</button>
    </div>
    <button id="submit-test" type="submit" class="btn btn-default btn-lg">Submit</button>
    <input type="hidden" id="payload">
  </form>

JS:

var testData = {
        "timestamp": "",
        "hive": 0,
        "hdfs": 0,
        "beacons":[]
    };

var testRun = document.getElementById("test-form");
    testRun.addEventListener('submit', function(event) {
        event.preventDefault();
        testData["timestamp"] = new Date().getTime();
        console.log(testData);
        var payload = document.getElementById("payload");
        payload.value = testData;
        $(this).trigger('submit', true);
    });

Currently, I cannot see the value I gave to <input type="hidden" id="payload"> which makes me to believe that it is not getting posted.

Liondancer
  • 15,721
  • 51
  • 149
  • 255

2 Answers2

4

You need to give the input a name:

<input type="hidden" id="payload" name="payload">

See this SO answer: Difference between id and name attributes in HTML

Community
  • 1
  • 1
Daniel Gimenez
  • 18,530
  • 3
  • 50
  • 70
1

You need to add a name attribute to your hidden tag.

The name is what you refer to it by.

<input type="hidden" name="payload" id="payload">
Joe Swindell
  • 684
  • 1
  • 7
  • 18