madmhan84 Posted December 28, 2017 Report Share Posted December 28, 2017 (edited) Good day & Happy Holidays I'd like to ask for a help on how to retain the values that I submitted using two buttons inside a table cell?This is the result when I click the two buttons in my form: This is the exact result I wanted (Note: Image below is just edited using a picture editor): This is the code that I used: <html> <head> <title>Sample </title> </head> <body> <table border = "1" align = "center" cellpadding = "10" > <form method = "post" action = "<?php echo $_SERVER['PHP_SELF']; ?>"> <tr> <td>Output1 : <?php if (isset($_POST['run1'])) { echo "<b>" .$_POST['input1']. "</b>"; } ?> </td> <td>Output2 : <?php if (isset($_POST['run2'])) { echo "<b>" .$_POST['input2']. "</b>"; } ?> </td> </tr> <tr> <td><input type = "text" name = "input1" value = "Type here..."></td> <td><input type = "text" name = "input2" value = "Type here..."></td> </tr> <tr> <td align = "center"><input type = "submit" name = "run1" value = "Button 1"></td> <td align = "center"><input type = "submit" name = "run2" value = "Button 2"></td> </tr> </form> </table> </body> </html> Edited December 28, 2017 by madmhan84 Quote Link to comment Share on other sites More sharing options...
administrator Posted January 2, 2018 Report Share Posted January 2, 2018 Hi, There are few basic ways to handle this: Using PHP sessions, where you capture the user input in session and then populate the form elements with that data on a post request. Using JS and DOM scripting to capture the text input and then insert it into the form element - your text box. jQuery has method that will make this easy. You can also look at client side JS frameworks like Reactjs and perhaps Angular too. Stef 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.
Note: Your post will require moderator approval before it will be visible.