Re: Passing variables in a multiple part form
| From: | Chris Lee | Date: | Wed, 03 Jan 2001 01:13:02 +0000 |
| Subject: | Re: Passing variables in a multiple part form | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-32430@lists.php.net to get a copy of this message | ||
Not sure if this is what you want or not...
<?
echo "<table border='2' cellpadding='3'
cellspacing='1'>\n";
for ($y = 0; $y < 2 AND $y < $roomcount; $y++)
{
echo "<tr>\n";
echo "<td width='100'><input type='text'
name='Room[$y][]'
size='20'></td>\n";
echo "<td width='100'><input type='text'
name='Room[$y][]'
size='20'></td>\n";
echo "<td width='100'><input type='text'
name='Room[$y][]'
size='20'></td>\n";
echo "<td width='100'><input type='text'
name='Room[$y][]'
size='20'></td>\n";
echo "</tr>\n";
}
echo "</table>\n";
?>
This will create a a multidimentional array
Room[0][0]
Room[0][1]
Room[0][2]
Room[0][3]
Room[1][0]
Room[1][1]
Room[1][2]
Room[1][3]
You can't have four variables all named Room1 and Room2 the client will only
accept the last one. This might have been what you wanted. if so change
Room[$y][]
to
Room$y
then you will only have two variables,
Room1
Room2
each will only contain the value typed into the last text box. ie line 9
thats it.
Chris Lee
Mediawaveonline.com
""Richard J. Mackey"" <mackeyrj@nettaxi.com> wrote in message
news:00a701c0751c$46879a80$0b00a8c0@localdomain...
I am using PHP3.016
I would like help in setting up the ability to pass a variable from one form
into the second part of the same form and then again to a third and perhaps
4th part of the same form. Basically I have a rough setup on mysite at
http://mackey-decorating.com/CSForm_start.php3
The first part works fine as does the second part. However after that the
variables that are created during the loop which makes the table and inserts
the textareas for data collection are lost when the function ends. The third
part of this form works only because I wrote the code for each individual
table cell. Very time consuming and inefficient.
(Sample)
$y=1;
Print " <table border=\"2\" cellpadding=\"3\"
cellspacing=\"1\">\n";
Print " <tr>\n";
Print " <td width=\"100\">\n";
if ($y<$roomcount)
{
print " $Room1\n";
Print " </td>\n";
Print "<td width=\"100\">\n";
print "<input type=\"text\" name=\"Room$y\"
size=\"20\">\n";
Print "</td>\n";
Print " <td width=\"100\">\n";
print "<input type=\"text\" name=\"Room$y\"
size=\"20\">\n";
Print "</td>\n";
Print "<td width=\"100\">\n";
Print "<input type=\"text\" name=\"Room$y\"
size=\"20\">\n";
Print " </td>\n";
Print " <td width=\"100\">\n";
print "<input type=\"text\" name=\"Room$y\"
size=\"20\">\n";
Print " </td>\n";
Print "</tr>\n";
Print " <tr>\n";
Print " <td width=\"100\">\n";
}
$y=$y+1;
if ($y<$roomcount)
{
print" $Room2\n";
Print " </td>\n";
Print "<td width=\"100\">\n";
print "<input type=\"text\" name=\"Room$y\"
size=\"20\">\n";
Print "</td>\n";
Print " <td width=\"100\">\n";
print "<input type=\"text\" name=\"Room$y\"
size=\"20\">\n";
Print "</td>\n";
Print "<td width=\"100\">\n";
Print "<input type=\"text\" name=\"Room$y\"
size=\"20\">\n";
Print " </td>\n";
Print " <td width=\"100\">\n";
print "<input type=\"text\" name=\"Room$y\"
size=\"20\">\n";
Print " </td>\n";
Print "</tr>\n";
Print " <tr>\n";
Print " <td width=\"100\">\n";
}
(End sample)
All help will be appreciated.