I am writing a php page that will process a form with unkonw number of elements. The number of form elements will depend on the records retrieved from mysql database (these elements will tell what the data type and user interface to be populated on form). I have named the form elements as arg1, arg2 etc... The problem is to process these elements. I used the following code to handles the form:
<?php
$count = count($_POST);
echo "number of elements: " . $count . "<br>";
echo "filter id: " . $_POST['fid'] . "<br>";
//first element is filter id and the last is submit
for($i=1;$i < $count-1;$i++){
$arg = "arg" . $i;
$value = $_POST[$arg];
if(is_array($value)){
for($j=0;$j<count($value);$j++){
$element .= $value[$j] . ", ";
}
$element = substr($element,0, strlen($element) -2);
echo "Getting array: " . $element;
}else{
echo "Getting $arg: " . $value;
}
echo "<br>";
}
?>
It works fine as long as the <select multiple> </select> element are selected. The element values after that <select></select> is lost if it does not have any value selected. Can any one offer me some advise?
Thanks,
Kuan Huang