Ell20 Posted March 28, 2008 Share Posted March 28, 2008 Hi, I have some code which includes some GETS, however each GET contains a submit button which display a message and performs a task. This is working fine however once the submit button is pressed the current GET is lost and it returns to the original page from which the message is also display on. How do I adapt the code so that when the submit button is pressed the message is displayed in the current GET and it doesnt refresh back to the original page? <?php if (isset($_POST['submit'])) { echo "<center>This is test 1</center>"; } if (isset($_POST['submit2'])) { echo "<center>This is test 2</center>"; } ?> <table align="center" border="1" cellpadding="0" cellspacing="0" width="60%" class="game"> <tr> <td colspan="4"> Testing </td> </tr> <tr height="50px" align="center"> <td> <a href='<?=$_SERVER['PHP_SELF']."?";?>&mode=test1'>Test1</a> </td> <td> <a href='<?=$_SERVER['PHP_SELF']."?";?>&mode=test2'>Test2</a> </td> </table> <?php if (isset($_GET['mode']) && $_GET['mode'] == 'test1') { ?> <table width="60%" align="center" cellspacing="0" border="0" class="game"> <tr> <th width="50%">Testing 1</th> </tr> <tr> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <td width="33%" align="center"><input name="submit" type="submit" value="Test" /></td> </form> </tr> </table> <?php } ?> <?php if (isset($_GET['mode']) && $_GET['mode'] == 'test2') { ?> <table width="60%" align="center" cellspacing="0" border="0" class="game"> <tr> <th width="50%">Testing 2</th> </tr> <tr> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <td width="33%" align="center"><input name="submit2" type="submit" value="Test 2" /></td> </form> </tr> </table> <?php } ?> Appreciate any help Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 28, 2008 Share Posted March 28, 2008 You need to append the GET value to the form action. Try this: <?php if (isset($_POST['submit'])) { echo "<center>This is test 1</center>"; } if (isset($_POST['submit2'])) { echo "<center>This is test 2</center>"; } ?> <table align="center" border="1" cellpadding="0" cellspacing="0" width="60%" class="game"> <tr> <td colspan="4"> Testing </td> </tr> <tr height="50px" align="center"> <td> <a href='?mode=test1'>Test1</a> </td> <td> <a href='?mode=test2'>Test2</a> </td> </table> <?php if (isset($_GET['mode']) && $_GET['mode'] == 'test1') { ?> <table width="60%" align="center" cellspacing="0" border="0" class="game"> <tr> <th width="50%">Testing 1</th> </tr> <tr> <form action="?mode=test1" method="post"> <td width="33%" align="center"><input name="submit" type="submit" value="Test" /></td> </form> </tr> </table> <?php } ?> <?php if (isset($_GET['mode']) && $_GET['mode'] == 'test2') { ?> <table width="60%" align="center" cellspacing="0" border="0" class="game"> <tr> <th width="50%">Testing 2</th> </tr> <tr> <form action="?mode=test2" method="post"> <td width="33%" align="center"><input name="submit2" type="submit" value="Test 2" /></td> </form> </tr> </table> <?php } ?> ....I also took out the PHP_SELFs as you can get away without them Quote Link to comment Share on other sites More sharing options...
Ell20 Posted March 28, 2008 Author Share Posted March 28, 2008 Excellent, thanks for your help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.