The code attached below, works, which asks for input on two items, then on submit, puts the values into a csv file on the php server.
I'd like to LOAD the LAST previous results, now the LAST line in the csv file, back INTO the form as DEFAULTS for the next round (So the 2 fields are populated with the values, and user can either press SUBMIT again, or make a change, and press SUBMIT to submit the newly changed values). If you know some simple coding to ADD to the code, to do the job, i'd love to see it... THANKS
BELOW is the file "FormTest-002.php" which calls itself when submitted...
<?php
if($_POST['formSubmit'] == "Submit")
{
$errorMessage = "";
if(empty($_POST['formGum']))
{
$errorMessage .= "<li>You didn't enter your favourite gum</li>";
}
if(empty($_POST['formName']))
{
$errorMessage .= "<li>You didn't enter your name</li>";
}
$varGum = $_POST['formGum'];
$varName = $_POST['formName'];
if(empty($errorMessage))
{
$fs = fopen("gumdata.csv","a");
fwrite($fs,$varName . ", " . $varGum . "\n");
fclose($fs);
header("Location: SubmitSuccessful.html");
exit;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>MyGUM Form</title>
</head>
<body>
<b>v1.01/18jan25/fj</b>
<?php
if(!empty($errorMessage))
{
echo("<p>There was an error with your form:</p>\n");
echo("<ul>" . $errorMessage . "</ul>\n");
}
?>
<form action="FormTest-002.php" method="post">
<p>
What is your favorite Gum?<br>
<input type="text" name="formGum" maxlength="35" value="<?=$varGum;?>" />
</p>
<p>
What is your name?<br>
<input type="text" name="formName" maxlength="35" value="<?=$varName;?>" />
</p>
<input type="submit" name="formSubmit" value="Submit" />
</form>
</body>
</html>