Sol Sol - 4 months ago 8
HTML Question

How can you get form post data with JQuery from the Post?

I have a hidden field where the question_id is unique. I am trying to get that hidden field within jquery from the next page so that I can post a message of the form status.

Then I will put that status in the HTML at the bottom of the form that was submitted.

form.php

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery File Upload</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>

function submitForm(upload_input_field){
upload_input_field.form.submit();
return true;
}
$(function () {
});
</script>
</head>
<body>
<form action="uploadFile.php" target="uploadIframe" method="post" enctype="multipart/form-data">
<input type='button' class='btn btn-default' onClick='submitForm(this)' value='Submit' />
<input name='question_id' value='123' type='hidden' />
</form>
<iframe style="border:0;" id="uploadIframe" name="uploadIframe"></iframe>
<div id="successMessage123"></div>
</body>
</html>


uploadFile.php

<?php $question_id = $_POST['question_id']; ?>
<script>
$(document).ready(function(){
$("[name=question_id]").val(var questionid);
//alert(question_id);
//$(('#successMessage_'+question_id), window.parent.document).html('<p>hidden value success</p>');
$('#successMessage_'+question_id).html('<p>hidden value success</p>');
});
</script>

Answer

Your JavaScript, which is client-side, (JQuery is a JS library) can only parse content rendered/output by the server(PHP). One easy solution would be inline PHP like this:

<?php   $question_id = $_POST['question_id']; ?>
  <script>
    $(document).ready(function(){
        $("[name=question_id]").val(<?=$question_id?>);
        $('#successMessage_'+question_id).html('<p>hidden value success</p>');
    });
</script>