Adding additional fields
Posted: Tue Oct 30, 2007 2:05 pm
Right now I have a form that takes in information. This form is set up to take 10 sets of the same information. If you fill in none, or some of the sets, it continues on. If you fill in all 10, it also continues on, but there is no option to enter in more than 10.
What I would like to have happen is the default sets you enter in be 1. Then if you need more you press an "Additional" button, or something, and it updates to give you another set that you can fill in.
The form will then be processed by a php script, which will need to know how many sets were created.
I'll attach the code for what I have already.
This is the processing script. Notice the use of $numberOfAdditionalRows to determine how many rows exist. This is just a static value right now.
This is the front end which displays the html form. $numberOfAdditionalRows is used again here.
I know php fairly well, but I'm not at all experienced with AJAX or JavaScript. All help is appreciated.
What I would like to have happen is the default sets you enter in be 1. Then if you need more you press an "Additional" button, or something, and it updates to give you another set that you can fill in.
The form will then be processed by a php script, which will need to know how many sets were created.
I'll attach the code for what I have already.
This is the processing script. Notice the use of $numberOfAdditionalRows to determine how many rows exist. This is just a static value right now.
Code: Select all
$numberOfAdditionalRows=10;
if($_SESSION['documentInfoSet'])
{
if(isset($_POST['Enter']))
{
$documentInfo=$_SESSION['documentInfo'];
$county=$documentInfo[1][0];
$c=2;
for($b=0;$b<$numberOfAdditionalRows;$b++)
{
$wasSet=FALSE;
$_POST['documentNumber'.$b]=removeBlankSpaces($_POST['documentNumber'.$b]);
if($_POST['documentNumber'.$b]!='')
{
if(validNumber($_POST['documentNumber'.$b]))
{
$documentInfo[$c][1]=$_POST['documentNumber'.$b];
$wasSet=True;
}
else
{
$error='Invalid Entry. Please make sure to only use numbers for Document Number, Volume, and Page.';
}
}
if($wasSet)
{
$documentInfo[$c][0]=$county;
$c++;
}
}
if(!isset($error))
{
if(isset($_SESSION['documentInfoSet']))
{
unset($_SESSION['documentInfoSet']);
}
$_SESSION['documentInfoSet']=TRUE;
$_SESSION['documentInfo']=$documentInfo;
header("Location: ./Upload.php", true, 302 );
}
}
}
?>This is the front end which displays the html form. $numberOfAdditionalRows is used again here.
Code: Select all
<form action="./Additional.php" method="post" name="form">
<table align="center" border="1">
<?php
for($a=0;$a<$numberOfAdditionalRows;$a++)
{
?>
<tr><th colspan="4"><?php echo ($a+1); echo ")";?></th></tr>
<tr>
<th> Document Number: </th>
<td> <input type="text" name="documentNumber<?php echo $a;?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="10" align="center">
<input type="submit" name="Enter" value="Enter" >
</td>
</tr>
</table>
</form>