Jump to content
Killersites Forums

How to retain the data submitted from a form?


madmhan84
 Share

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:
output1.jpg

This is the exact result I wanted (Note: Image below is just edited using a picture editor):
output2.jpg

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 by madmhan84
Link to comment
Share on other sites

Hi,

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. 

Stef

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.

Guest
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.

Loading...
 Share

×
×
  • Create New...