Reputation: 67
I get data from an html5 form using php and i am trying to keep data of the fields and not be cleared.
It is working for inputs but is failing for textarea(description field).
You can see below that i add a php echo as a value inside the inputs but it's not working for textarea. How can i make this work for textarea as well?
HTML form:
<form method='post' action='entry.php' enctype="multipart/form-data">
<label for="username"> Username: </label>
<input type="text" name="username" id="username" value="<?php echo $username; ?>" /></br>
</br>
<label for="email">Email:</label>
<input type="email" name="email" value="<?php echo $email; ?>"/> </br></br>
<label>Title of monument:</label>
<input type="textbox" name="title" value="<?php echo $title; ?>" /></br></br>
<label>Description of monument:</label>
<textarea cols="50" rows="6" name="description" value="<?php echo $description; ?>" /></textarea></br></br>
<label>Select image:</label>
<input type="file" name="file" ></br></br>
<input type="submit" value="Submit" name="submit" >
</form>
Upvotes: 2
Views: 2675
Reputation: 3047
Replace
textarea cols="50" rows="6" name="description" value="<?php echo $description; ?>" ></textarea>
with
<textarea cols="50" rows="6" name="description" ><?php echo $description; ?></textarea>
I added the php echo inside the textarea elements and i removed it from the textarea value attribute. It should do the work.
Upvotes: 3
Reputation: 1945
You have closed the textarea tag:
<textarea cols="50" rows="6" name="description" />
Need to remove the closing slash, so your php will be inserted into the textarea!
<textarea cols="50" rows="6" name="description" > <?php ... ?> </textarea>
Upvotes: 0
Reputation: 943100
The value of a textarea element is determined by the text node inside it, not by a value attribute.
<textarea cols="50" rows="6" name="description"><?php
echo htmlspecialchars($description);
?></textarea>
Upvotes: 2
Reputation: 10907
Textareas don't have a value property.
Instead, you're supposed to put the value directly between the <textarea>
and </textarea>
tags.
Like so:
<textarea cols="50" rows="6" name="description"><?php
echo htmlspecialchars($description);
?></textarea>
And you also need to pass $description
through htmlspecialchars()
, in case the value in $description
contains HTML tags like other <textareas>
or so.
Upvotes: 1