I've found many solutions regarding similar question but unfortunately none of them solve mine. The form is working fine except the textarea. The form does not post the textarea value, it shows
undefined index: description
this is the html code:
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group">
<label>Description</label>
<textarea name="description" rows="4" cols="50" class="form-control" value=""></textarea>
</div>
</form>
php
$description = $_POST['description'];
Does anyone know where the problem lies? Thanks in advance.
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.