Textarea value not getting posted with form
try to put it inside the form tag as follows... it should work
<form action="sendConfirmation.php" name="confirmationForm" method="post">
<textarea id="confirmationText" class="text" cols="86" rows ="20" name="confirmationText"></textarea>
<input type="submit" value="Email" class="submitButton">
</form>
however you can use the same approach as well but you need to provide the from id attribute then
<form action="sendConfirmation.php" id="confirmationForm" method="post">
<input type="submit" value="Email" class="submitButton">
</form>
Textarea not posting value in form
Always ensure you test that the submit button
has been clicked before accessing the values of your form fields using the isset
function. This is because as the server load the page the server attempt to retrieve the value of the inputs field which have not yet been entered. as such undefined
. Another solution is to use another page to handle your form submission.
<?php
if(isset($_POST['submit'])){
$age = $_POST['age'];
$description = $_POST['description'];
}
?>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group">
<input name="age" />
<label>Description</label>
<textarea name="description" rows="4" cols="50" class="form-control" value=""></textarea>
<button name="submit" value="save">Save</button>
</div>
</form>
Textarea doesn't keep its contents after a form submission
The main problem you are facing is that you are POSTing to a different script, and then doing header("location: index.php");
back to index.php. This loses all $_POST vars, and there is no way to add them into the header redirect (browsers POST, not server header redirects).
So, you need to change your direction...
Since you are already stuffing the textarea content in a session variable $_SESSION['Text']
, you can use this on your index.php:
<textarea name="TextArea" ...otherstuff... ><?php
echo (!empty($_SESSION['Text']) ? htmlspecialchars($_SESSION['Text']) : '' );
unset($_SESSION['Text']);// optionally clear after re-iterating it
?></textarea>
Some caveats you need to address in your ProcessText.php
page though:
- Move
session_start();
to the very top before any html or echo output. - Add
session_write_close();
before yourheader();exit;
. - Heck, all that 'html' above your
header()
needs to go as well.
If you don't want to use sessions... because some expert told you they are terribly unreliable and useless:
A) POST to the same page that will be re-displaying your form (ie index.php)
or
B) Setting up a main branch script which handles all submits, but has no html of its own. This then would do a straight include('index.php');
of which page you should be given (thus the $_POST vars will exist). However this method requires a bit of planning and discipline in setting up all your scripts and html blocks.
textarea values not posting with form
You cannot post form elements with disabled
attribute. Instead use readonly
on them. Eg:
<textarea id="sources" name="sources" readonly>
And you can style them like disabled
using CSS:
[readonly] { /* style as disabled */ }
Or, have a same name with hidden <input />
fields:
<textarea id="sources" name="sources" disabled>
<input type="hidden" value="^ textarea's value" name="sources" />
Cannot get the value of a textarea via post method
It is because you need to name the textarea:
<textarea name="txtcomment"></textarea>
The id
parameter does not have anything to do with how forms work (with the exception of label
s, but that is not important here).
Unable to post the content inside my textArea which is inside the form which sends POST REQUEST
So I found a solution to my problem in this post:
Here
What I needed to do, is to add a form id="composeForm" to my form and then use that same id
inside the textarea(attribute: form="composeForm")
HTML
<form action="/compose" method="post" id="composeForm">
<div style="margin-bottom: 1rem; margin-top: 2rem;">
<label for="exampleInputEmail1" class="form-label">Title</label>
<input type="text" name="postTitle" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
</div>
<div>
<label class="form-label" for="textAreaExample">Post</label>
<textarea name="postBody" id="textAreaExample" cols="150" rows="10" class="form-control" form="composeForm"></textarea>
</div>
<button type="submit" name="button" class="btn btn-primary" class="mt-4"
style="margin-top: 1rem;">Publish</button>
Related Topics
Are Nested HTML Comments Possible
Can't Show Some Websites in Iframe Tag
Should I Use <Ul>S and <Li>S Inside My <Nav>S
How to Tell Browsers to Honor The Jpeg Exif Orientation
How to Use a Grammar with The HTML 5 Speech Input API
How Does Stackoverflow Make Its Tag Input Field
How to Display a Range Input Slider Vertically
How to Always Show Up/Down Arrows for Input "Number"
Youtube Video Header Background
Can a: :Before Selector Be Used with a <Textarea>
2 Colors in One Placeholder of Input Field
How to Communicate Between Frames
Why Would The Height Increase with a Smaller Font Size
What Is The Correct Readonly Attribute Syntax for Input Text Elements