Jump to content

Recommended Posts

Hey guys, I have to have 4 identical forms, and I was curious if this is possible?

 

for ($counter = 1; $counter < 5; $counter += 1) {
echo "<form name='friends' action='thanks.php' method='post'>";
echo "<table>\n";
echo "\t<tr>\n";
echo "\t\t<td>".$counter.". Name: <input name='name[".$counter."]' type='text' size='20'> Address: <input name='address[".$counter."]' type='text' size='25'></td>\n";
echo "\t</tr>\n";
echo "\t<tr>\n";
echo "\t\t<td>City: <input name='city[".$counter."]' type='text' size='15'> State: <input name='state[".$counter."]' type='text' maxlength='2' size='2'> Zip: <input name='zip[".$counter."]' type='text' maxlength='5' size='5'></td>\n";
echo "\t</tr>\n";
echo "\t<tr>\n";
echo "\t\t<td>Email: <input name='email[".$counter."]' type='text' size='20'> Phone: <input name='phone[".$counter."]' type='text' maxlength='12' size='10'><small> 555-555-5555</small></td>\n";
echo "\t</tr>\n";
echo "</table>\n";
if($counter != 4) {
	echo "<hr />\n";
}
}

 

This prints out 4 forms pefectly, but my problem is:  How do I get the info on the next page?  I've tried

foreach($_POST['name'] as $k => $v) {

--and--

for($counter = 1; $counter < 5; $counter += 1) {
$name.$counter = $_POST['name'][$counter];
}

 

I know these don't work,  but I'm not sure how to get the info.  I can do this all manually, but I guess I'm being lazy.  Thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/88916-solved-is-this-form-possible/
Share on other sites

Form:

 

<?php
echo "<form name='friends' action='thanks.php' method='post'>";
for ($counter = 1; $counter < 5; $counter += 1) {
echo "<table>\n";
echo "\t<tr>\n";
echo "\t\t<td>".$counter.". Name: <input name='name[".$counter."]' type='text' size='20'> Address: <input name='address[".$counter."]' type='text' size='25'></td>\n";
echo "\t</tr>\n";
echo "\t<tr>\n";
echo "\t\t<td>City: <input name='city[".$counter."]' type='text' size='15'> State: <input name='state[".$counter."]' type='text' maxlength='2' size='2'> Zip: <input name='zip[".$counter."]' type='text' maxlength='5' size='5'></td>\n";
echo "\t</tr>\n";
echo "\t<tr>\n";
echo "\t\t<td>Email: <input name='email[".$counter."]' type='text' size='20'> Phone: <input name='phone[".$counter."]' type='text' maxlength='12' size='10'><small> 555-555-5555</small></td>\n";
echo "\t</tr>\n";
echo "</table>\n";
if($counter != 4) {
	echo "<hr />\n";
}
}
echo "</form>";
?>

 

the PHP script:

<?php
  for($counter = 1; $counter < 5; $counter += 1) {
    echo "Results for {$counter}:\n";
    foreach($_POST as $key=>$val)
      echo "{$key}: {$val[$counter]}\n";
  }
?>

 

hope that helps

Hi

 

Hope this helps

 

put this on your main page

<?
for ($c = 1; $c <= 4; $c ++) 
{?>
<form name='friends' action='thankyou.php' method='post'>
<table>
<tr>
<td><?=$c?> Name: <input name='name<?=$c?>' type='text' size='20'> Address: <input name='address<?=$c?>' type='text' size='25'></td>
</tr>
<tr>
<td>City: <input name='city<?=$c?>' type='text' size='15'> State: <input name='state<?=$c?>' type='text' maxlength='2' size='2'> Zip: <input name='zip<?=$c?>' type='text' maxlength='5' size='5'>
</td>
</tr>
<tr>
<td>Email: <input name='email<?=$c?>' type='text' size='20'> Phone: <input name='phone<?=$c?>' type='text' maxlength='12' size='10'><small> 555-555-5555</small>
</td>
</tr>
</table>
<?
if($c != 4) {
	echo "<hr />";
}
}
//added
?>
<input name="count" type="hidden" value="<?=$c?>" />



<label>
<input type="submit" name="Submit" value="Send to next page" />
</label>
</form>

 

put this on your thank you page.

<?
for($i=1;$i< $_POST['count'];$i++)
{
echo 'Name :'.$_POST['name'.$i] ; 
echo '<br/>' ;
echo 'Address :'.$_POST['address'.$i] ; 
echo '<br/>' ;
echo 'City :'.$_POST['city'.$i] ;
echo '<br/>' ;
echo 'State :'.$_POST['state'.$i] ; 
echo '<br/>' ;
echo 'Zip :'.$_POST['zip'.$i] ;
echo '<br/>' ;
echo 'E-Mail :'.$_POST['email'.$i] ;
echo '<br/>' ;
echo 'Phone :'.$_POST['phone'.$i] ;
echo '<br/>' ; 
echo '<hr/>' ; 
}
?>

 

cheers

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.