Page 1 of 1
Displaying a form Multiple times
Posted: Mon Jul 21, 2008 5:52 am
by shotos
Hi
i want a form to be displayed a number of times(on each occasion accepting inputs).
but the number of times it is displayed is entered by the user.
thanks
Re: Displaying a form Multiple times
Posted: Mon Jul 21, 2008 3:00 pm
by califdon
shotos wrote:Hi
i want a form to be displayed a number of times(on each occasion accepting inputs).
but the number of times it is displayed is entered by the user.
thanks
Do you mean displaying one form at a time, as many times as requested, or do you mean displaying several copies of the same form on the same page at the same time?
Re: Displaying a form Multiple times
Posted: Mon Jul 21, 2008 3:10 pm
by shotos
thanks for the response.
what i mean is the user enters how many entries he wld want to make
then the form is displayed for him to make the first entry, after the data entered
is stored and the form is re-displayed again until all entries have been entered.
Only then will the entry data be written into the database
Re: Displaying a form Multiple times
Posted: Mon Jul 21, 2008 3:40 pm
by califdon
shotos wrote:thanks for the response.
what i mean is the user enters how many entries he wld want to make
then the form is displayed for him to make the first entry, after the data entered
is stored and the form is re-displayed again until all entries have been entered.
Only then will the entry data be written into the database
It's easy enough to ask for the number of forms and loop that many times, but what you have to be concerned about is saving the data, if you want to make a single update to the database. You'd probably need to use an array for that.
Re: Displaying a form Multiple times
Posted: Mon Jul 21, 2008 4:15 pm
by shotos
Ok, i got it to loop the required number of times but problem is
the array suppose to hold the data is always empty.
i tired several options to try to get an output............
this is the code
Code: Select all
<?php
session_start();
ob_start();
if(!isset($_POST['submit'] ))
{
?>
<head>
<link rel="stylesheet" type="text/css" href="new.css" />
<title>Checklist System</title>
</head>
<body>
<div id="container">
<div id="banner">
<h1>Checklist System</h1>
</div>
<div id="nav"color="backgrounds/blue01">
Welcome <?php echo $_SESSION['user'] ?><br><br><br>
<a href="view_users.php">View Users</a><br><br><a href="create_User.php">Create User Accounts</a><br><br><a href="edit_delete_user.php">Edit/Delete User</a><br><br><a href="end.php">Generate Checklist</a><br><br><a href="login_success.php">View all Checklists</a><br><br><br><a href="log_out.php">Sign Out</a>
</div>
<div id="content">
<h2>Enter Check Items for New Checklist</h2>
<form method="POST" action="<?php $_SERVER['PHP_SELF']?>">
<table border="0" align="center" cellpadding="10" cellspacing="10">
<tr>
<td>Check Item: <input type="text" name="checkItem"></td></tr>
<tr>
<td><input type="radio" name="element" value="radio">Radio Button<br></td>
</tr>
<tr>
<td><input type="radio" name="element" value="checkbox">Checkbox<br></td>
</tr>
<tr>
<td><input type="radio" name="element" value="text">Textbox<br></td>
</tr>
<tr>
<td> </td></tr>
<tr><td><h3>Enter Labels for the chosen checklist element</h3></td></tr>
<tr>
<td>Label 1: <input type="text" name="label1"></td></tr>
<tr><td>Label 2: <input type="text" name="label2"></td></tr>
<tr><td>Label 3: <input type="text" name="label3"></td></tr>
<tr><td> </td></tr>
<tr>
<td ><input type="hidden" id="num" name="num" value="<?php echo $_SESSION['count'];?>">
</td></tr>
<tr>
<td align="center"><input type="submit" name="submit" value="Submit">
</td></tr>
</table>
</form>
<div id="footer">
uni-duisburg 2008 <blink align="right">Last Updated: 06.07.08</blink>
</div>
</div>
</body>
<?php
}
else
{
$num = $_POST['num'];
$check_item[] = $_POST['checkItem'];
$check_item[] = $_POST['element'];
$check_item[] = $_POST['label1'];
$check_item[] = $_POST['label2'];
$check_item[] = $_POST['label3'];
/*foreach($_POST as $var)
{
$check_item[] = $var;
}*/
$_SESSION["$num"] = $check_item ;
//unset($_POST);
$_SESSION['count'] = ++$num ;
if($num > $_SESSION['num_Items'])
{
header("location:checking1.php?item=$check_item");
}
else
{
header("location:checking.php");
}
}
ob_flush();
?>
Re: Displaying a form Multiple times
Posted: Mon Jul 21, 2008 4:49 pm
by califdon
Two suggestions:
1. I would use a 2-dimensional array, so you can easily manipulate it, rather than just successive values. This can be done something like this (I'm not all that good with arrays, either, but I think this is right):
Code: Select all
$num = $_POST['num'];
$check_item[$num,'checkitem'] = $_POST['checkItem'];
$check_item[$num,'element']] = $_POST['element'];
$check_item[$num,'label1']] = $_POST['label1'];
$check_item[$num,'label2']] = $_POST['label2'];
$check_item[$num,'label3']] = $_POST['label3'];
2. Get familiar with PHP's print_r() function for echoing back the contents of an array, like:
It will reveal what's in the array in an easy-to-read format.
Re: Displaying a form Multiple times
Posted: Mon Jul 21, 2008 5:48 pm
by shotos
thanks,
it did work but needed some modifications
so i am pasting the revised version .....
Code: Select all
$num = $_POST['num'];
$check_item[$num]['checkitem'] = $_POST['checkItem'];
$check_item[$num]['element'] = $_POST['element'];
$check_item[$num]['label1'] = $_POST['label1'];
$check_item[$num]['label2'] = $_POST['label2'];
$check_item[$num]['label3'] = $_POST['label3'];
Re: Displaying a form Multiple times
Posted: Mon Jul 21, 2008 7:41 pm
by califdon
Of course!!

I told you I'm rusty on arrays, I keep remembering syntax from other programming languages. I think the comma notation was used in some language I used to use. Anyway, glad you got it working and thanks for posting the corrected syntax.