I have absolutely no idea where to put this, as it encompasses php and javascript, but I think the former is more applicable as I am having trouble accessing hidden variables passed
to the next webpage.
What I am trying to do is this: I have a webpage that manipulates some data using javascript, and these data are then passed immediately (without user prompting) to the next page, where a php page picks up the hidden values.
What I have so far is:
transfer_file.php
Code: Select all
<html>
<body>
<script type="text/javascript">
jsvar=10;
document.form1.data.value = jsvar;
/* Just a test - alter the hidden value */
</script>
<form method="POST" name="form1" action="transfer_file2.php">
<input type='hidden' name='data' value=''>
</form>
function sendData()
{
//alert(document.form1.data.value);
document.form1.submit();
}
<?php
header("Location: transfer_file2.php"); // immediately forward the user to the next page
?>
</body></html>Code: Select all
<?php
$myvar = $_POST['data'];
echo "myvar: ".$myvar;
?>Notice: Undefined index: data in C:\wamp\www\transfer_file2.php on line 2
myvar:
Can someone please help suggest a fix?
Thanks!
Paul