how use textarea input for post - php

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>

Related

I am trying to use an HTML form to append the results to a Text file using php

Here is my HTML form
<html>
<body>
<h1>HTMl FORM</h1>
<p>
<form action="example.php" method="POST">
<p>Your First name: <input type="text" name="fname" /></p>
<p>Your Last name : <input type="text" name="lname" /></p>
<p><input type="Submit" name="Submit" value="Submit" /> <input type="Reset”/></p>
</form>
</p>
</body>
</html>
PHP file "example.php" Shows the Client what was inputted and should append to the text file "phpfile.txt"
<html>
<body>
<p>
Hi <?php echo htmlspecialchars($_POST['fname']); ?>.<br>
<?php echo htmlspecialchars($_POST['lname']); ?>
</p>
<?php
if(isset($_POST['Submit'])){
$fname = $_POST['fname']."
";
$lname = $_POST['lname']."
";
$file=fopen("phpfile.txt", "a");
fwrite($file, $fname);
fwrite($file, $lname);
fclose($file);
}
?>
</body>
</html>
I am getting the php file to print for the user but it is not appending to the .txt file. I am unsure where I am going wrong
You are probably getting a syntax error.
You also need to use \n to add a new line. You also need to place the echo $_POST parts in the isset function.
<html>
<body>
<h1>HTMl FORM</h1>
<p>
<form action="" method="POST">
<p>Your First name: <input type="text" name="fname" /></p>
<p>Your Last name : <input type="text" name="lname" /></p>
<p><input type="Submit" name="Submit" value="Submit" />
<input type="Reset"/>
</p>
</form>
</p>
<?php
if(isset($_POST['Submit'])){
echo 'Hi '.htmlspecialchars($_POST['fname']);
echo '<br>';
echo htmlspecialchars($_POST['lname']);
$fname = $_POST['fname']."";
$lname = $_POST['lname']."";
$file=fopen("phpfile.txt", "a");
fwrite($file, $fname." ".$lname. "\n");
fclose($file);
}
?>
</p>
</body>
</html>

PHP Post not getting information back

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

submitting result to the end of the url instead of adding an index.php

Id basically like the below submission to place text at the end of the url
example of what i want
http://example.com/(text) -- without the () obviously
example of what i don't want -- http://www.example.com/index.php?firstname=text
<form action="(end of current url)">
<fieldset>
search name
<br>
<input type="text" name="search" value="name">
<br>
<input type="submit" value="Submit"></fieldset>
</form>
id like to fix this via html or php either will do aslong as it submits the request to that :)
thank you in advance.
Using the POST method instead of GET.
<form action="" method="POST">
<fieldset>
search name
<br>
<input type="text" name="search" value="name">
<br>
<input type="submit" value="Submit"></fieldset>
</form>
In short you do the following:
<?php
// Get posted text
$text = strtolower(mysql_real_escape_string($_POST['text']));
// Do some cleanup here
// Redirect to page
if ($text != ''){
header( 'Location: http://www.example.com/' . $text );
}
// HTML output below (not before)
?>
<form method="post" action="">
<fieldset>
Search name<br />
<input type="text" name="text" /><br />
<input type="submit" value="Submit" />
</fieldset>
</form>

PHP,HTML Need to direct from one form to another form

I have written a code to get First name,last name and NIC no. If First name is missing I will show a error call "missing" infront of the textbox. All this thing is working and it will send the information in to the same page.
If first name is missing show the error in the same form which will allow user to refill it. If the user entered information correctly, I need to redirect user to another form. How can I do it?
<?php
$fnameerr="";
$name="";
if($_SERVER['REQUEST_METHOD']=="POST")
{
if(empty($_POST["fname"]))
{
$fnameerr="Missing";
}
}
?>
<head>
<title>Untitled Document</title>
</head>
<body>
<form name="form1" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
First Name:<input type="text" name="fname" value="<?php echo htmlspecialchars($name);?>">
<span class="error" style="color:#FF0000">*<?php echo $fnameerr;?></span>
<br/><br/>
Last Name:<input type="text" name="lname" /><br/><br/>
NIC:<input type="text" name="nic" /><br/><br/>
<input type="submit" name="sub" value="Register"/>
<input type="reset" name="re" value="Reset"/>
</form>
</body>
</html>
Use header() to redirect
if(empty($_POST["fname"])) {
$fnameerr="Missing";
}
else {
header("Location: anotherForm.php");
}

How can i pass values from two html pages to php?

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>

Categories