My Problem is:
I want to get the value of textbox1 then transfer it to another page where the value of textbox1 will be appeared in the textbox2.
Below is my codes for PHP:
<html>
<body>
<form name='form' method='post' action="testing2.php">
Name: <input type="text" name="name" id="name" ><br/>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
I also add the code below and the error is "Notice: Undefined index: name"
<?php
$name = $_GET['name'];
echo $name;
?>
or
<?php
$name = $_POST['name'];
echo $name;
?>
Use PHP's $_POST or $_GET superglobals to retrieve the value of the input tag via the name of the HTML tag.
Here is the code of the form with decode script. $t1v=$_GET['t1v']; $t1v=urldecode($t1v); echo " <form method=post action=pb-t. php> <input type=text name=t1 value='$t1v'> <input type=submit value=Submit> "; ?>
PHP - Keep The Values in The Form To show the values in the input fields after the user hits the submit button, we add a little PHP script inside the value attribute of the following input fields: name, email, and website. In the comment textarea field, we put the script between the <textarea> and </textarea> tags.
php $a = $_GET["housemodel"]; if($a<>'') { if($a == $model1) { echo "<input type=\"text\" name=\"a\" value=\"something model1\">"; } else if($a == $model2) { echo "<input type=\"text\" name=\"b\" value=\"something model2\">"; } else if($a == $model3) { echo "<input type=\"text\" name=\"c\" value=\"something model3\">"; ...
In testing2.php use the following code to get the name:
if ( ! empty($_POST['name'])){
$name = $_POST['name']);
}
When you create the next page, use the value of $name
to prefill the form field:
Name: <input type="text" name="name" id="name" value="<?php echo $name; ?>"><br/>
However, before doing that, be sure to use regular expressions to verify that the $name only contains valid characters, such as:
$pattern = '/^[0-9A-Za-zÁ-Úá-úàÀÜü]+$/';//integers & letters
if (preg_match($pattern, $name) == 1){
//continue
} else {
//reload form with error message
}
I think you should need to check for isset and not empty value, like form was submitted without input data so isset will be true This will prevent you to have any error or notice.
if((isset($_POST['name'])) && !empty($_POST['name']))
{
$name = $_POST['name']; //note i used $_POST since you have a post form **method='post'**
echo $name;
}
You are posting the data, so it should be $_POST. But 'name' is not the best name to use.
name = "name"
will only cause confusion IMO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With