Jump to content
Killersites Forums

How to retain the data submitted from a form?


Recommended Posts

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:

<title>Sample </title>

<table border = "1" align = "center" cellpadding = "10" >
<form method = "post" action = "<?php echo $_SERVER['PHP_SELF']; ?>">

<td>Output1 : 
	if (isset($_POST['run1'])) {
		echo "<b>" .$_POST['input1']. "</b>"; 

<td>Output2 : 
	if (isset($_POST['run2'])) {
		echo "<b>" .$_POST['input2']. "</b>"; 

<td><input type = "text" name = "input1" value = "Type here..."></td>
<td><input type = "text" name = "input2" value = "Type here..."></td>

<td align = "center"><input type = "submit" name = "run1" value = "Button 1"></td>
<td align = "center"><input type = "submit" name = "run2" value = "Button 2"></td>




Edited by madmhan84
Link to comment
Share on other sites


There are few basic ways to handle this:

  1. Using PHP sessions, where you capture the user input in session and then populate the form elements with that data on a post request.
  2. Using JS and DOM scripting to capture the text input and then insert it into the form element - your text box.
  3. jQuery has method that will make this easy. 

You can also look at client side JS frameworks like Reactjs and perhaps Angular too. 


Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...