943,700 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2178
  • PHP RSS
Oct 8th, 2005
0

PHP question regarding Forms

Expand Post »
Hi all

Here is a PHP question I have to answer.

Quote ...
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
apcxpc is offline Offline
55 posts
since Sep 2004
Oct 8th, 2005
0

Re: PHP question regarding Forms

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.
Reputation Points: 10
Solved Threads: 7
Posting Whiz in Training
zippee is offline Offline
294 posts
since Jan 2005
Oct 8th, 2005
0

Re: PHP question regarding Forms

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
apcxpc is offline Offline
55 posts
since Sep 2004
Oct 8th, 2005
0

Re: PHP question regarding Forms

<?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>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cthackers is offline Offline
2 posts
since Oct 2005
Oct 9th, 2005
0

Re: PHP question regarding Forms

cthackers, can you do my homework too please?
Reputation Points: 10
Solved Threads: 1
Junior Poster
sarahk is offline Offline
138 posts
since Apr 2005
Oct 9th, 2005
0

Re: PHP question regarding Forms

Quote originally posted by sarahk ...
cthackers, can you do my homework too please?
Now apcxpc, you just gotta optimize your homework..
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Oct 10th, 2005
0

Re: PHP question regarding Forms

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:
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
apcxpc is offline Offline
55 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP Session
Next Thread in PHP Forum Timeline: Loop through result set





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC