dfowler Posted February 1, 2008 Share Posted February 1, 2008 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 More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 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 Link to comment https://forums.phpfreaks.com/topic/88916-solved-is-this-form-possible/#findComment-455442 Share on other sites More sharing options...
avo Posted February 1, 2008 Share Posted February 1, 2008 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 Link to comment https://forums.phpfreaks.com/topic/88916-solved-is-this-form-possible/#findComment-455469 Share on other sites More sharing options...
dfowler Posted February 1, 2008 Author Share Posted February 1, 2008 Thanks guys, I incorporated a little bit from both of you and got the results I was looking for! Link to comment https://forums.phpfreaks.com/topic/88916-solved-is-this-form-possible/#findComment-455505 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.