Doubling forms
Moderator: General Moderators
Doubling forms
I'm not to sure how I should start this. Nor do I have an example that I can show you, so I will just try my best to explain.
Here's what I need to do.
How many input boxes would you like ? [ 1-10 ]
now accorind to what was entered in the { } that number of boxes shows up on the screen.
This would be used for extra upload input boxes and extra lines in a form.
I just want to copy the fields and have then have their own out puts.
Here's what I need to do.
How many input boxes would you like ? [ 1-10 ]
now accorind to what was entered in the { } that number of boxes shows up on the screen.
This would be used for extra upload input boxes and extra lines in a form.
I just want to copy the fields and have then have their own out puts.
If you do it by asking the question, then submitting the results via $_POST it would look like this.
ing the results via $_POST it would look like this.
Code: Select all
$inputnumber = $_POST['numberentered'];
echo "<form action=\"page.php\" method=\"method\">";
for($i=1; $i<$inputnumber; $i++)
{
echo "<input type=\"type\" name=\"name\">";
}
echo "<input type=\"submit\" value=\"submit\">";
echo "</form>";Code: Select all
$inputnumber = $_POST['numberentered'];
echo "<form action=\"page.php\" method=\"method\">"e;;
for($i=1; $i<$inputnumber; $i++)
{
echo "e;<input type=\"e;type\"e; name=\"e;name\"e;>"e;;
}
echo " like this.Code: Select all
$inputnumber = $_POST['numberentered'];
echo "<form action=\"page.php\"e; method=\"e;method\"e;>"e;;
for($i=1; $i<$inputnumber; $i++)
{
echo "<input type=\"type\" name=\&amOST['numberentered'];
echo "<form action=\"page.php\" method=\"method\">";
for($i=1; $i<$inputnumber; $i++)
{
echo "e;<input type=\"e;type\"e; name=\"e;na
$inputnumber = $_POST['numberentered'];
echo "<form action=\"page.php\" method=\"method\">";
for($i=1; $i<$inputnumber; $i++)
{
echo "<input type=\"type\" name=\"name\">";
}
echo "<input type=\"submit\" value=\"submit\">";
echo "</form>";I got these two so far. Go through form.php, choose 2 or 3 then press the first submit. Enter image name, Enter link, Enter comment for all fields. then submit.
Now notice that only the last field that you have filled out only shows. Why is that ?
Form
output
Now notice that only the last field that you have filled out only shows. Why is that ?
Form
Code: Select all
<?php
if (!isset($_POSTї'submit']))
{
echo '
<form action="e;"e; method="e;POST"e;>
How many input boxes would you like?<br>
<select name="e;number"e;>
';
for ($i = 1; $i <= 10; $i++)
{
echo '<option>' . $i;
}
echo '
</select><br>
<input type="e;submit"e; name="e;submit"e; value="e;submit"e;>
</form>
';
}
else
{
for ($i = 1; $i <= $_POSTї'number']; $i++)
{
echo $i . '.<br>';
echo '
<form action="e;output.php"e; method="e;post"e; >
<td width="e;5%"e;>Image</td>
<td width="e;16%"e;> <input type="e;text"e; name="e;imagename"e;></td>
<td width="e;4%"e;>Link</td>
<td width="e;16%"e;><input type="e;text"e; name="e;filelink"e;></td>
<td width="e;7%"e;>comments</td>
<td width="e;52%"e;> <TEXTAREA NAME="e;comments"e; COLS=50 ROWS=1 WRAP=VIRTUAL></TEXTAREA>
</td>
<BR><BR>
';
}
}
echo '<input type="e;submit"e; name="e;Submit"e; value="e;Submit"e;>
<input name="e;Reset"e; type="e;reset"e; id="e;Reset"e; value="e;Reset"e;>';
?>
</form>Code: Select all
<?
$filename = $_POSTї"e;imagename"e;];
$filelink = $_POSTї"e;filelink"e;];
$comments = $_POSTї"e;comments"e;];
?>
<!-- end PHP -->
<html>
<head>
<title>output</title>
<meta http-equiv="e;Content-Type"e; content="e;text/html; charset=iso-8859-1"e;>
</head>
<body>
<br>
<? echo $imagename; ?> <br>
<? echo $filelink; ?> <br>
<? echo $comments; ?> <br>
</p>Because each row of boxes uses the same name for the form elements, whatever you enter in the earlier boxes gets wiped out. Plus you've wrapped each set of boxes in its own form element.
You'll probably want to do something like:
On the form generation page -- Now you have a single form with multiple sets of controls.
Then on the receiving page, you need to loop, using $_POST["numberOfBoxes"] and re-create the full names.
You'll probably want to do something like:
Code: Select all
echo "
<form action=\"output.php\" method=\"post\" >
<input type=\"hidden\" name=\"numberOfBoxes\" value=\"{$_POST["number"}\" />
";
for ($i = 1; $i <= $_POST['number']; $i++)
{
$row=<<<END_ROW
<tr>
<td width="5%">Image</td>
<td width="16%"> <input type="text" name="imagename-$i"></td>
<td width="4%">Link</td>
<td width="16%"><input type="text" name="filelink-$i"></td>
<td width="7%">comments</td>
<td width="52%"> <TEXTAREA NAME="comments-$i" COLS=50 ROWS=1 WRAP=VIRTUAL></TEXTAREA>
</td>
</tr>
END_ROW;
echo $row;
}
. . .Then on the receiving page, you need to loop, using $_POST["numberOfBoxes"] and re-create the full names.
I think I got everythign working ok. jUst one minor detail
How would I get the result to display horizontaly instead of vertically ?
so it's
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 ... and so on..
1 2 3 4 5 6 7 8
not like this
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
How would I get the result to display horizontaly instead of vertically ?
so it's
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 ... and so on..
1 2 3 4 5 6 7 8
not like this
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
Code: Select all
<?php
if (!isset($_POSTї'submit']))
{
echo '
<form action="e;"e; method="e;POST"e;>
step 1:<br>
How many input boxes would you like?<br>
<select name="e;number"e;>
';
for ($i = 1; $i <= 10; $i++)
{
echo '<option>' . $i;
}
echo '
</select><br>
<input type="e;submit"e; name="e;submit"e; value="e;go to step 2"e;>
<form>
';
}
if (isset($_POSTї'submit']) && $_POSTї'submit'] == 'go to step 2')
{
echo '
<form action="e;"e; method="e;POST"e;>
step 2:<br>
<table border="e;1"e;>
<tr>
<td>#</td>
<td>image:</td>
<td>link:</td>
<td>comments:</td>
</tr>
';
for ($i = 1; $i <= $_POSTї'number']; $i++)
{
echo '
<tr>
<td>' . $i . '.</td>
<td><input type="e;text"e; name="e;dataї' . $i . ']їimagename]"e;></td>
<td><input type="e;text"e; name="e;dataї' . $i . ']їfilelink]"e;></td>
<td><textarea name="e;dataї' . $i . ']їcomments]"e; cols="e;50"e; rows="e;1"e; wrap="e;virtual"e;></textarea></td>
</tr>
';
}
echo '
</table>
<input type="e;submit"e; name="e;submit"e; value="e;go to step 3"e;>
</form>
';
}
if (isset($_POSTї'submit']) && $_POSTї'submit'] == 'go to step 3')
{
echo ' <table width="e;82"e; border="e;0"e; align="e;center"e; cellpadding="e;5"e; cellspacing="e;5"e;>
';
foreach ($_POSTї'data'] as $key => $value)
{
echo '
<tr><td>' . $valueї'imagename'] . '</td></tr>
<tr> <td>' . $valueї'filelink'] . '</td></tr>
<tr> <td> <font face="e;Arial, Helvetica, sans-serif"e;
size=2> ' . $valueї'comments'] . ' </font> </td></tr>
';
}
echo '</table>';
}
?>