Reputation: 1
I have a form set into my html page:
<form action='savephp.php' name="writingData" id="writingData" method="post">
<textarea id="content">Hello, World!</textarea>
<input type="submit" value="submit" class="submitButton">
</form>
and the receiving php is:
<?php
$data = $_POST['writingData'];
if ($data === NULL) {
echo 'is null';
}
else {
file_put_contents("writingdata.txt", $data);
echo $data;
}
?>
However, I get the "is null" error every time I attempt to post. Im hitting a dead end, Ive tried changing up the form name
, using the textarea id
. I keep getting a null response. Any ideas what I am missing?
Upvotes: 0
Views: 75
Reputation: 53
textarea needs a name attribute
<textarea id="content" name="txtareaContent"></textarea>
then you can fetch it in savephp.php like this
$data = $_POST['txtareaContent'];
Upvotes: 1
Reputation: 1
<form action='savephp.php' name="writingData" id="writingData" method="post">
<textarea id="content" name=="content">Hello, World!</textarea>
<input type="submit" value="submit" class="submitButton">
</form>
<?php
$data = $_POST['content'];
if ($data === NULL) {
echo 'is null';
}
else {
file_put_contents("writingdata.txt", $data);
echo $data;
}
?>
Try this and let me know.
Upvotes: 0