| | |
PHP question regarding Forms
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hi all
Here is a PHP question I have to answer.
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.
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.
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.
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.
<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.
•
•
Join Date: Oct 2005
Posts: 2
Reputation:
Solved Threads: 0
<?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>
$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>
•
•
•
•
Originally Posted by sarahk
cthackers, can you do my homework too please?
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
- Newbie php question. how to create a mailing list? (MySQL)
- Simple PHP Question (PHP)
- Windows Forms Question (C#)
- Html+PHP Forms (PHP)
- Upadating booking page with php (PHP)
- Zend PHP Certification (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP Session
- Next Thread: Loop through result set
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error fcc file files folder form forms function functions google howtowriteathesis href htaccess html image images include insert integration ip java javascript joomla ldap limit link login loop mail menu methods mlm mod_rewrite multiple multipletables mysql oop open parse paypal pdf php problem query radio random recursion regex remote script search server sessions sms soap source space speed sql structure syntax system table template tutorial update upload url validation validator variable video web xml youtube






