I am trying to create a simple online form using html and php tooutput to a .csv. I have no problem doing this for a single form but the users of this form will usually have multiple entries at once. To make it easier for them I am using a form of which you can add lines to submit more entries in one submission. Below is the HTML and PHP code.
The issue I am having is the PHP part. I can only get it to ever submit the first entry.
Any ideas? I have a working version of the site/form here, but again, only the first entry every gets entered into the .csv. Thanks for the help.
HTML:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="mdcstyle.css" />
<title>Submission form</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type='text/javascript'>
//<![CDATA[
$(document).ready(function() {
var currentItem = 0;
$('#addnew').click(function(){
currentItem++;
$('#items').val(currentItem);
var strToAdd = '<tr><td>Area:<input class="textfield" name="area'+currentItem+'" id ="area'+currentItem+'"type="text" /></td><td>Contractor:<input class="textfield" name="contractor'+currentItem+'" id ="contractor'+currentItem+'"type="text" /></td></tr>';
$('#data').append(strToAdd);
});
});
//]]>
</script>
</head>
<body>
<div class="content">
<h2>header text</h2>
<p>Please complete this form for Udpates. Add a new line if you have more than one project.</p>
<form id="myform" name="form1" method="post" action="signup2.php">
<table class="dd" width="100px" id="data">
<tr>
<td>Area:<input class="textfield" name="area0" id="area0" type="text" /></td>
<td>Contractor:<input class="textfield" name="contractor0" id="contractor0" type="text" /></td>
</tr>
</table>
<input class="subbutton" type="submit" name="Submit" value="Submit Form">
</form>
<button id="addnew" name="addnew" value="Add new item">Add new entry</button>
<input type="hidden" id="items" name="items" value="1" />
<br>
</div>
</body>
</html>
PHP:
<?php
for( $i = 0; $i <= $count; $i++ )
{
date_default_timezone_set('America/New_York');
$today = date("m.d.y");
$area0 = $_POST['area'.$i];
//the data
$data = "$today, $area0, $contractor, $hours, $project, $town, $street
";
//open the file and choose the mode
$fh = fopen("users2.csv", "a");
fwrite($fh, $data);
//close the file
fclose($fh);
}
?>