This question already has answers here:
how to remember input data in the forms even after refresh page?
(10 answers)
Closed 3 years ago.
Hi I am new to PHP and here I am developing a mulit page form, but as soon as page is refreshed, entered data is disappeared, below code is I am writing.
<?php
if(isset($_POST['name'])){
echo $_POST['name'].'<br/>';
}
?>
<form method="POST" action="">
<p>NAME</p>
<input type="text" name="name" value="<?php
if(isset($_POST['name'])){
echo htmlentities ($_POST['name']);
}
?>" />
<br/>
<input type="submit" value="keep value" name="submit"/> <br/>
</form>
Modify your code like this.
<?php
if(isset($_POST['name'])){
$name = $_POST['name']; // After form submit store value in $name variable to keep this value in input box
echo $_POST['name'].'<br/>';
}else{
$name = ""; // Store empty value if the form is not submit
} ?>
<form method="POST" action="">
<p>NAME</p>
<input type="text" name="name" value="<?php $name; ?>" />
<br/>
<input type="submit" value="keep value" name="submit"/> <br/>
Related
This question already has answers here:
How do I make a PHP form that submits to self?
(6 answers)
Closed 6 years ago.
I am trying to submit a form by post method on itself. but every time the form submits and page is refreshed. it doesn't show values.
<?php echo $_POST['fname']; ?>
<form method="POST" action='#.php'>
<input type="text" name="fname" id="fname" />
<button id="check" name="check" type="submit">GO</button>
</form>
What's the point, i am missing?
Try this :
<?php echo $_POST['fname']; ?>
<form method="POST" action=""> <!-- not single quote -->
<input type="text" name="fname" id="fname" />
<input type="submit" name="value" >
</form>
Try this...
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "<pre>";
print_r($_POST);
}
?>
<form name="test" action="" method="post"><input type="text" name="firstName" /><input type="submit" name="Submit" /></form>
I would recommend to write more cleaner way. like this:
<?php
if(isset($_POST['fname']) && !empty($_POST['fname']) ){
echo $_POST['fname'];
}
?>
<form method="POST" action=""> <!-- not single quote -->
<input type="text" name="fname" id="fname" />
<input type="submit" name="value" >
</form>
This question already has answers here:
Make a link use POST instead of GET
(11 answers)
Closed 7 years ago.
Is there a way to replicate this in <a href="blah.php">?
<form action="http://localhost/php/suburb_added.php" method="post">
<b>Add a New Suburb</b>
<p>Name:
<input type="text" name="suburb" size="30" value="" />
<input type="submit" id="submit" value="Submit" name="submit" />
</p>
</form>
in suburb_added.php... i have this to capture
if (!empty($_POST['suburb']))
To a table form....
<td align="left"><a href="suburb_added.php"><?php echo $row['id'];?></td>
how to create the items below from a table? The goal is when I click the result from <?php echo $row['id'];?>, I should be able to get the value of "id" and process it in suburb_added.php using similar to if (!empty($_POST['suburb']))
<form action="http://localhost/php/suburb_added.php" method="post">
<input type="text" name="suburb" size="30" value="" />
what do you whant i don't understand?? I can help you
<?php
if(!isset($_POST['submit'])){
?>
<form action="" method="post" name="submit">
<b>Add a New Suburb</b>
<p>Name:
<input type="text" name="suburb" size="30" value="" />
<input type="submit" id="submit" value="Submit" name="submit" />
</p>
</form>
<?php
} else {
//paste here your code from http://localhost/php/suburb_added.php
echo "you doing post in this page.";
}
?>
<!--Try using header
like this:-->
if($_POST)
{
header('location:login-form.php');
}
else
{
echo "";
}
Change the PHP script so it uses $_REQUEST instead of $_POST. This variable combines the contents of $_POST and $_GET. Then you can have a link like
<?php echo $row['id'] ?>
I am facing a problem while self posting form data, when I hit submit button the page should display the data inserted in the input box,
but it does not show the data....
Here is my example form
<?php
if($_SERVER['REQUEST_METHOD']=='POST')
{
$mail = $_POST['mail'];
echo $mail;
}
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="myForm">
Mail : <input id="mail" name="mail" type="text"/>
<input type="submit" value="Submit"/>
</form>
This should obviously display the mail value from the input box. But it does not work. Then I tried to change the action attribute value to "mywordpress/index.php/customer-details-2/"
Since I am new with Wordpress, any help would be highly appreciated.
Add the posted value in your input text box as :
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="myForm">
Mail : <input id="mail" name="mail" type="text" value="<?php echo (isset($_POST['mail'])) ? $_POST['mail'] : '' ?>" />
<input type="submit" value="Submit" />
</form>
I am assuming that you want to show data inside input text box.
Hope it helps you.
I'm just learning about html and php but it doesn't work. Could anyone point me in the right direction:
My form:
<form action="" method="post">
<p>Your name: <input type="text" name="name" /></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
</form>
PHP:
Hi <?php echo htmlspecialchars($_POST['name']); ?>.
You are <?php echo (int) $_POST['age']; ?> years old.
When I click submit the page loads to the same page but it doesn't pick up either name or email.
I've also tried adding:
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
But when I click submit it brings up a 404 error with:
<?php%20echo%20htmlspecialchars($_SERVER[
in the last bit of my URL?
Any help would be highly appreciated.
PHP:
Hi <?php echo $_POST['name']; ?>.
You are <?php echo $_POST['age']; ?> years old.
In input type of age write:
<input type='number' ....
This question already has answers here:
How to read the query string in PHP and HTML?
(3 answers)
Closed 9 years ago.
My URL is /mithun/add.php?bc=3
The "bc" being the attribute name. How can I pass this value so that it shows me the value 3 as input on the screen.
My source code:
<body>
<h1>Add new product</h1>
<form action="add.php" method="post">
Barcode: <input type="text" name="bc" />
<input type="submit" name="submit" value="submit" />
</form>
</body>
Thanks in advance.
Replace text type with this Barcode: <input type="text" name="bc" value ="<?php echo $_GET['bc']?>" />
You can access it also from url portion like
<?php $arr = explode("=",$_SERVER['REQUEST_URI']);
echo $arr[1];
?>
<input type="text" name="bc" value ="<?php echo $arr[1];?>" />
you can first get the value by $_GET['bc'] and then echo in the input type and its always good to see weather the $_GET['bc'] is set or not and escape it you can do this by
<input type="text" name="bc" value ="<?php
if( isset($_GET['bc']) && ctype_digit($_GET['bc']))
echo $_GET['bc'];
else
echo "other default" ; ?> />
and if you want to pass value from url use GET method instead
<body>
<h1>Add new product</h1>
<form action="add.php" method="post">
Barcode: <input type="text" name="bc" value="<?php echo $_GET['bc']; ?>" />
<input type="submit" name="submit" value="submit" />
</form>
</body>