denisb wrote:
Roderik <ma**@roderik.net> wrote:
The problem is, how can I use the javascript array in this php file?
Is it neccesary to use numerous hidden form fields for this purpose?
cause javascript is executed on client browser and php script on server
: yes.
you have 3 methods for passing javascript values to your php script :
1- hidden (or not) fields of a form ;
2- link with url like www.script.php?var1=val1&var2=val2...
/!\ : you must serialize ?var1=val1&var2=val2... :
3- cookie string
further to roderick's reply:
an array passed back to the server in a hidden form field will arrive in
your PHP script as a comma-delimited list, either in a POST variable, or
a GET variable.
this example uses the POST method --
<form name="testForm" action="test.php" method="post">
<input type="text" name="testText">
<input type="hidden" name="testHidden">
<input type="submit">
</form>
<script language="javascript">
testArray = new Array (1,2,3);
document.testForm.testHidden.value = testArray;
</script>
<?php
if (isset($_POST['testHidden'])) {
$tok = strtok($_POST['testHidden'], ",");
while ($tok) {
echo "element = $tok<br>";
$tok = strtok (",");
}
}
?>