I've put together a little script that works fine in general, it just needs a minor fix and some Ajax code. Basically, it appends a couple of forms to each output line. Submission works properly, 2 POSTS and 1 GET. But I'd like it to happen without a page refresh, ergo the Ajax code. I've tried messing around with some but the multiple variables are making it a nightmare. Here's the full code, first the main page:
<html>
<head>
<title></title>
</head>
<body>
<?php
$lines = file('file.txt');
foreach ($lines as $line) {
$field = explode("|", $line);
$name = $field[0];
$id = $field[4];
echo $name . '<br>';?>
<form method="post" action="submit-here.php?id=<?php echo $id;?>">
<select name="FORM1" size="3">
<option value="Value-1">Value-1</option>
<option value="Value-2">Value-2</option>
<option value="Value-3">Value-3</option></select>
<select name="FORM2" size="3">
<option value="Value-4">Value-4</option>
<option value="Value-5">Value-5</option>
<option value="Value-6">Value-6</option></select>
<br><br><input type="submit" value="submit" name="submit">
</form>
<?php
}
?>
</body>
</html>
file.txt
is just your usual DSV flat file i.e. field1|field2|field3|field4\n
Which brings me to the required minor fix I mentioned, namely the line break at the end of each row generates a pair of "phantom" forms after every legitimate form pair, add more line breaks and get more ghost code, I tried using preg_replace and if...else to filter them out but without success.
submit-here.php:
$id = $_GET["id"];
$FORM1 = $_POST["FORM1"];
$FORM2 = $_POST["FORM2"];
$write = $id . '|' . $FORM1 . '|' . $FORM2 . "\n";
$fn = "file2.txt";
$fh = fopen($fn, 'a');
fwrite($fh, $write);
fclose($fh);