Page 1 of 1

Doubling forms

Posted: Sun Jul 17, 2005 1:43 am
by jackjack
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.

Posted: Sun Jul 17, 2005 2:36 am
by djot
-
Do you know how to upload single/multiple files?

If so, it should be no problem to use some loop function (for, foreach, while) for building up variable (upload-) forms.

djot
-

Posted: Sun Jul 17, 2005 3:23 am
by jackjack
Nothign is uploading.

It for a new update form that I have name. I just need it do you a " how many updates of this do you want" thing added.

Posted: Sun Jul 17, 2005 5:51 am
by phpScott
would you like to do it with or without submiting the page?

if you submit the page then create a function that will create that many checkboxes(or whatever) as html code and dispaly it.

not submiting the page would require javascript and just alittle more work.

Posted: Sun Jul 17, 2005 12:51 pm
by s.dot
If you do it by asking the question, then submitting 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>";
ing the results via $_POST it would look like this.

Code: Select all

$inputnumber = $_POST['numberentered'];

echo "<form action=\"page.php\" method=\"method\"&gt;&quote;;

for($i=1; $i&lt;$inputnumber; $i++)
{
    echo &quote;&lt;input type=\&quote;type\&quote; name=\&quote;name\&quote;&gt;&quote;;
}

echo &quot like this.

Code: Select all

$inputnumber = $_POST['numberentered'];

echo "<form action=\"page.php\&quote; method=\&quote;method\&quote;&gt;&quote;;

for($i=1; $i&lt;$inputnumber; $i++)
{
    echo "<input type=\"type\" name=\&amOST['numberentered'];

echo "<form action=\"page.php\" method=\"method\">";

for($i=1; $i<$inputnumber; $i++)
{
    echo &quote;&lt;input type=\&quote;type\&quote; name=\&quote;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>";

Posted: Mon Jul 18, 2005 1:17 am
by jackjack
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

Code: Select all

<?php 
if (!isset($_POST&#1111;'submit'])) 
{ 
    echo ' 
    <form action=&quote;&quote; method=&quote;POST&quote;> 
    How many input boxes would you like?<br> 
    <select name=&quote;number&quote;> 
    '; 
    for ($i = 1; $i <= 10; $i++) 
    { 
        echo '<option>' . $i; 
    } 
    echo ' 
    </select><br> 
    <input type=&quote;submit&quote; name=&quote;submit&quote; value=&quote;submit&quote;> 
    </form> 
    '; 
} 
else 
{ 
    for ($i = 1; $i <= $_POST&#1111;'number']; $i++) 
    { 
echo $i . '.<br>'; 
 
echo '
<form action=&quote;output.php&quote; method=&quote;post&quote; >
      <td width=&quote;5%&quote;>Image</td>
      <td width=&quote;16%&quote;> <input type=&quote;text&quote; name=&quote;imagename&quote;></td>
      <td width=&quote;4%&quote;>Link</td>
      <td width=&quote;16%&quote;><input type=&quote;text&quote; name=&quote;filelink&quote;></td>
      <td width=&quote;7%&quote;>comments</td>
      <td width=&quote;52%&quote;> <TEXTAREA NAME=&quote;comments&quote; COLS=50 ROWS=1 WRAP=VIRTUAL></TEXTAREA>
	    </td>



<BR><BR>
';

 } 
} 

echo '<input type=&quote;submit&quote; name=&quote;Submit&quote; value=&quote;Submit&quote;>
          <input name=&quote;Reset&quote; type=&quote;reset&quote; id=&quote;Reset&quote; value=&quote;Reset&quote;>';
?> 


</form>
output

Code: Select all

<?

$filename = $_POST&#1111;&quote;imagename&quote;];
$filelink = $_POST&#1111;&quote;filelink&quote;];
$comments = $_POST&#1111;&quote;comments&quote;];

?>




<!-- end PHP  -->

<html>
<head>
<title>output</title>
<meta http-equiv=&quote;Content-Type&quote; content=&quote;text/html; charset=iso-8859-1&quote;>
</head>

<body>


<br>
    <? echo $imagename; ?> <br>
    <? echo $filelink; ?>  <br>
    <? echo $comments; ?> <br>
</p>

Posted: Mon Jul 18, 2005 1:57 am
by nielsene
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:

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;
}
. . .
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.

Posted: Mon Jul 18, 2005 5:07 pm
by jackjack
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


Code: Select all

<?php 
if (!isset($_POST&#1111;'submit'])) 
{  
    echo '     
    <form action=&quote;&quote; method=&quote;POST&quote;> 
    step 1:<br> 
    How many input boxes would you like?<br> 
    <select name=&quote;number&quote;> 
    ';  
       
    for ($i = 1; $i <= 10; $i++) 
    { 
        echo '<option>' . $i; 
    }  
       
    echo ' 
    </select><br> 
    <input type=&quote;submit&quote; name=&quote;submit&quote; value=&quote;go to step 2&quote;> 
    <form> 
    ';  
} 

if (isset($_POST&#1111;'submit']) && $_POST&#1111;'submit'] == 'go to step 2') 
{  
    echo '     
    <form action=&quote;&quote; method=&quote;POST&quote;> 
    step 2:<br> 
    <table border=&quote;1&quote;> 
    <tr> 
    <td>#</td> 
    <td>image:</td> 
    <td>link:</td> 
    <td>comments:</td> 
    </tr> 
    '; 
     
    for ($i = 1; $i <= $_POST&#1111;'number']; $i++)  
    {  
        echo ' 
        <tr> 
        <td>' . $i . '.</td> 
        <td><input type=&quote;text&quote; name=&quote;data&#1111;' . $i . ']&#1111;imagename]&quote;></td> 
        <td><input type=&quote;text&quote; name=&quote;data&#1111;' . $i . ']&#1111;filelink]&quote;></td> 
        <td><textarea name=&quote;data&#1111;' . $i . ']&#1111;comments]&quote; cols=&quote;50&quote; rows=&quote;1&quote; wrap=&quote;virtual&quote;></textarea></td> 
        </tr> 
        '; 
    } 
     
    echo ' 
    </table> 
    <input type=&quote;submit&quote; name=&quote;submit&quote; value=&quote;go to step 3&quote;> 
    </form> 
    '; 
} 

if (isset($_POST&#1111;'submit']) && $_POST&#1111;'submit'] == 'go to step 3') 
{ 
    echo ' <table width=&quote;82&quote; border=&quote;0&quote; align=&quote;center&quote; cellpadding=&quote;5&quote; cellspacing=&quote;5&quote;>
    
    '; 
         
    foreach ($_POST&#1111;'data'] as $key => $value) 
    { 
        echo ' 
        

<tr><td>' . $value&#1111;'imagename'] . '</td></tr>
<tr> <td>' . $value&#1111;'filelink'] . '</td></tr>
<tr> <td> <font face=&quote;Arial, Helvetica, sans-serif&quote; 
                        size=2> ' . $value&#1111;'comments'] . ' </font> </td></tr>

        '; 
    } 
     
    echo '</table>'; 
} 
?>