PHP question regarding Forms

Reply

Join Date: Sep 2004
Posts: 55
Reputation: apcxpc is an unknown quantity at this point 
Solved Threads: 0
apcxpc's Avatar
apcxpc apcxpc is offline Offline
Junior Poster in Training

PHP question regarding Forms

 
0
  #1
Oct 8th, 2005
Hi all

Here is a PHP question I have to answer.

Write a php file called reload.php that contains a table with 2 rows and 3 columns. In each of the cells of the top row of this table there should be the strings AAA, BBB & CCC. In the second row of this table there should be 3 submit buttons labeled ONE, TWO & THREE.

When the user presses one of these buttons, the same reload.php page should load, such that the string above the pressed button moves to the top left cell and the other two cells are filled with strings one further in the sequence. E.g. if the user presses the button below the string BBB, then the new page should have cells filled with the values BBB, CCC, DDD. If, in this page, the user now presses the button below the string DDD, the reloaded page should display the strings DDD, EEE, FFF. If the sequence ever gets beyond ZZZ, then it should wrap back to AAA.
Now the thing I'm having a problem with is...
When the form is submitted and the page reloads, how do I determine which button was pressed/which string was "chosen"? How would I structure that bit? I simply cannot of something that would work.

Would appreciate any help/ideas on this. Thanks.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: PHP question regarding Forms

 
0
  #2
Oct 8th, 2005
In the submit button tag, you can define a "name" to it. For example,
<input name="AAA" value="Choose This" type="submit">

To capture which button was clicked. Use
if(isset($_POST['AAA']))
{
// your script
}

If this doesn't work, then you may use three separate form for the table.
Ecommerce-Web-Store.com Building Your e-Business.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 55
Reputation: apcxpc is an unknown quantity at this point 
Solved Threads: 0
apcxpc's Avatar
apcxpc apcxpc is offline Offline
Junior Poster in Training

Re: PHP question regarding Forms

 
0
  #3
Oct 8th, 2005
Excellent. Thank you so much, zippee. I had tried something along those lines, with trying to get the value of the button, but I messed it up somehow, so I thought it didn't work with buttons at all.

Thanks again.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 2
Reputation: cthackers is an unknown quantity at this point 
Solved Threads: 0
cthackers cthackers is offline Offline
Newbie Poster

Re: PHP question regarding Forms

 
0
  #4
Oct 8th, 2005
<?php
$s=array('AAA','BBB','CCC','DDD','EEE','FFF','GGG','HHH','III','JJJ','KKKK','...','ZZZ'); $nr=count($s);
if (isset($_POST['posted'])) {
if (isset($_POST['ONE']))
{
$position=array_search($_POST['c1'],$s);
$c1=$s[$position];
if ($position==$nr-1) { $position=0; } else { $position=$position+1; }
$c2=$s[$position];
if ($position==$nr-1) { $position=0; } else { $position=$position+2; }
$c3=$s[$position];
}
if (isset($_POST['TWO']))
{
$position=array_search($_POST['c2'],$s);
$c1=$s[$position];
if ($position==$nr-1) { $position=0; } else { $position=$position+1; }
$c2=$s[$position];
if ($position==$nr-1) { $position=0; } else { $position=$position+2; }
$c3=$s[$position];
}
if (isset($_POST['THREE'])) {
$position=array_search($_POST['c3'],$s);
$c1=$s[$position];
if ($position==$nr-1) { $position=0; } else { $position=$position+1; }
$c2=$s[$position];
if ($position==$nr-1) { $position=0; } else { $position=$position+2; }
$c3=$s[$position];
}
} else {
$c1='AAA';
$c2='BBB';
$c3='CCC';
}
?>
<form name="form1" action="reload.php" method="post">
<table width="50%" border="1" cellspacing="0" cellpadding="1">
<tr>
<td align="center"><?php echo $c1; ?><input name="c1" type="hidden" value="<?php echo $c1; ?>"></td>
<td align="center"><?php echo $c2; ?><input name="c2" type="hidden" value="<?php echo $c2; ?>"></td>
<td align="center"><?php echo $c3; ?><input name="c3" type="hidden" value="<?php echo $c3; ?>"></td>
</tr>
<tr>
<td align="center"><input name="ONE" type="submit" id="ONE" value="ONE"></td>
<td align="center"><input name="TWO" type="submit" id="TWO" value="TWO"></td>
<td align="center"><input name="THREE" type="submit" id="THREE" value="THREE">
<input name="posted" type="hidden" value="posted"></td>
</tr>
</table>
</form>
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 138
Reputation: sarahk is an unknown quantity at this point 
Solved Threads: 1
sarahk's Avatar
sarahk sarahk is offline Offline
Junior Poster

Re: PHP question regarding Forms

 
0
  #5
Oct 9th, 2005
cthackers, can you do my homework too please?
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,073
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: PHP question regarding Forms

 
0
  #6
Oct 9th, 2005
Originally Posted by sarahk
cthackers, can you do my homework too please?
Now apcxpc, you just gotta optimize your homework..
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 55
Reputation: apcxpc is an unknown quantity at this point 
Solved Threads: 0
apcxpc's Avatar
apcxpc apcxpc is offline Offline
Junior Poster in Training

Re: PHP question regarding Forms

 
0
  #7
Oct 10th, 2005
LOL yeah. I tried to do it for myself afterwards, and ran into some troubles again. I'm probably going to have to take a few peeks at my homework to figure it out. :lol:
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC