I’m having trouble submitting some hidden form data via post from the following function:
function displayCertificate()
{
window.open("../mailer.php","certificate","width=500,height=400,status=1")
}
var sHTML = "";
sHTML += '<FORM id="quizResults" method="POST" action="/articulate/mailer.php" enctype="text/plain" target="certificate" onSubmit="displayCertificate()">';
sHTML += '<INPUT TYPE="hidden" NAME="name" VALUE=\'' + g_arrResults[0].strStudentResponse + '\'>';
sHTML += '<INPUT TYPE="hidden" NAME="email" VALUE=\'' + g_arrResults[1].strStudentResponse + '\'>';
sHTML += '<br><input type="submit"><br>';
sHTML += '</FORM>';
alert(g_arrResults[0].strStudentResponse);
document.getElementById("divEmail").innerHTML = sHTML;
document.getElementById("quizResults").submit();
What I need is for a new window to open up with the information I sent to it via POST. The window pops up fine, and firebug shows that the POST was successful but the data doesn’t seem to be sent to my new window.
Here is my mailer.php:
<?php
print("name: ".htmlspecialchars($_POST['name']));
print("email: ".htmlspecialchars($_POST['email']));
?>
Very simple yet it is outputting: name: email:
Can anyone see why this would be happening? My solution has to be plain javascript (so no libraries please).
Thanks.
edit in response to alessioalex:
Output of console.log(g_arrResults) is an array like so:
[QuestionResult { nQuestionNum=1, strQuestion=" ", more...}, QuestionResult { nQuestionNum=2, strQuestion=" ", more...}, QuestionResult { nQuestionNum=3, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=4, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=5, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=6, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=7, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=8, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=9, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=10, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=11, strQuestion="A, B or C?", more...}, QuestionResult { nQuestionNum=12, strQuestion="A, B or C?", more...}]
Here is an example of the first object in the array:
bFound
false
dtmFinished
Date {Thu Nov 17 2011 12:54:29 GMT+0000 (GMT Standard Time)}
nPoints
"0"
nQuestionNum
1
strCorrectResponse
" "
strInteractionId
"I4e28818f-4014-418c-a6e4-863679014098"
strLatency
"1862"
strObjectiveId
"I4e28818f-4014-418c-a6e4-863679014098"
strQuestion
" "
strResult
"neutral"
strStudentResponse
"Peter Rabbit"
strType
"fillin"
Remove the window.open code and try adding target=”_blank” to your form: