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' ....
Related
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/>
use the input tag to send the data. I need a bigger area to write the comment, but how to make the comment in the textarea to be sent when the button is pressed?
<form action="action.php" method="post">
<p>Your name: <input type="text" name="name" /></p>
<p>your comment:<textarea name="comment" >Enter text here...</textarea></p>
<p><input type="submit" /></p>
</form>
the second part
name: <?php echo htmlspecialchars($_POST['name']); ?>.
comment: <?php echo htmlspecialchars($_POST['comment']); ?>.
Remove the (int)
Add rows and columns parameters to textarea
Add name to submit button
Add condition if (isset($_POST['submitbutton']))
My code for this question:
<html>
<head></head>
<body>
<form action="#" method="post">
<p>Your name: <input type="text" name="name" /></p>
<p>your comment:<textarea name="comment" rows="HEIGHT" cols="WIDTH">Enter text here...</textarea></p>
<p><input type="submit" name="submitbutton"/></p>
<?php
if (isset($_POST['submitbutton']))
{
echo htmlspecialchars($_POST['name']);
echo htmlspecialchars($_POST['comment']);
}
?>
</form>
</body>
</html>
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 have 2 html pages :
page1.html
<html>
<body>
<form action="page2.html" method="post">
Enter First name: <input type="text" id="text1">
<input type="submit" value="Next">
</form>
</body>
</html>
page2.html
<html>
<body>
<form action="test.php" method="post">
Enter Last name: <input type="text" id="text2">
<input type="submit" value="Submit">
</form>
</body>
</html>
Now, i would like to retrieve the value of text1 from page1.html and text2 from page2.html. How can i go about it?
Looks like you are looking for forms. See this tutorial http://www.w3schools.com/php/php_forms.asp. Post your form data from page1.php to page2.php. On page2.html you can access them via $_POST.
Please be aware: This is not a secure example, just for showing purposes! When you want to show user generated data in your frontend, please use sanitizing and validation http://www.php.net/manual/en/filter.examples.sanitization.php.
page1.php:
<form action="page2.php" method="post">
Enter first name: <input type="text" name="firstName"><br>
<input type="submit">
</form>
page2.php
<h1>Hey <?php echo $_POST['firstName']; ?></h1>
<form action="lastpage.php" method="post">
Enter last name: <input type="text" name="lastName"><br>
<input type="hidden" name="firstName" value="<?php echo $_POST['firstName']; ?>">
<input type="submit">
</form>
lastpage.php
<h1>Yo, my mate <?php echo $_POST['firstName']; ?> <?php echo $_POST['lastName']; ?>!</h1>
i tried to do some practise about form actions and inputs and copy-paste a piece of codes but i got Undefined index: fname and Undefined index: age. The codes were taken from very popular php tutorial website, there should not be any problem with them but submitting them anyway.Is this server error or something like that?
<form action="posting.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
<?php
echo $_POST["fname"];
echo $_POST["age"];
?>
You need to make sure $_POST is getting information before you try to read from it. There are a variety of ways to do this. Here's one:
<form action="posting.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
<?php
if(isset($_POST)) {
echo $_POST["fname"];
echo $_POST["age"];
}
?>
Until that form is submitted, $_POST is empty and trying to read anything out of it will result in such a notice.
<?php
if (isset($_POST['fname']) && isset($_POST['age'])) {
echo $_POST['fname'];
echo $_POST['age'];
}