Setting Value of Text Area - php

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>

Related

I cannot echo text from sql table into input textarea box correctly

In my table there is a column Content with text:
<h2>LAGU</h2><p>Pada minggu ke kota.<br />Naik delman.</p><p>Pak kusir.</p>
This Content column collation is latin_swedish_ci and type is Text in the phpMyAdmin table structure.
In my PHP page, after the query - I give it a name $content
HTML:
<?php echo $content ?>
<form action="update.php" method="post" enctype="multipart/form-data">
<div id="div_content">
<label id="label_content">Content</label>
<textarea id="content" name="content" value="<?php echo $content ?>"></textarea>
</div>
</form>
The content did show correctly in the first echo. What is in header tag, shown as a header. What is in paragraph tag shown as a paragraph.
But the second echo (which is inside the textarea box), it doesn't show at all. I'm expecting that the textarea box will show exactly the same like the text from the php table, so in case there is a typo or something - the user can edit it directly inside the textarea box.
I've tried one apostrophe instead of double apostrophe
<textarea id="content" name="content" value='<?php echo $content; ?>'></textarea>
The textarea box still empty.
I've tried also this for the textarea
<textarea id="content" name="content" value='.<?php echo $content ?>.'></textarea>
and this
<textarea id="content" name="content" value="'.<?php echo $content ?>.'"></textarea>
Still empty.
But after I've tried this:
<textarea id="content" name="content" value=<?php echo $content ?>></textarea>
The text area box show like this:
LAGU</h2><p>Pada minggu ke kota.<br />Naik delman.</p><p>Pak kusir.</p>>
It lost the 'h2' tag in the beginning. And at the end it reads the closing '>' for the <textarea .....
But the weirdest thing is, if in the PhpMyAdmin I change the table content column by typing dar der dor (just plain text without any weird character), the textarea box is empty no matter what trick I did in the php page.
FYI, besides $content - I also have $title. In phpMyAdmin table, the title column text is MAMA. I put in the php page like this:
<input type="text" id="title" name="title" value="<?php echo $title ?>">
And the inputbox show MAMA.
Change this line:
<textarea id="content" name="content" value="<?php echo $content ?>"></textarea>
to
<textarea id="content" name="content"><?php echo $content; ?></textarea>
and try again.
Explanation: texarea don't have value attribute in it. The value you see is the innerHTML of textarea. So what ever you want to print is between <textarea><?php echo $content; ?></textarea>
There is no value attribute for the textarea element, the value must be placed inside the textarea element.
This is should be your solution:
<?php echo $content ?>
<form action="update.php" method="post" enctype="multipart/form-data">
<div id="div_content">
<label id="label_content">Content</label>
<textarea id="content" name="content"><?php echo $content; ?></textarea>
</div>
</form>

Post method does not return value of textarea

Problem with the post method.
I have a html form where i use textarea as disabled and the value of the textarea comes from the database with the help of another page.
<textarea disabled name="sms" id="sms">
<?php echo $value; //Here the value of textarea and it shows on it?>
</textarea>
My PHP code is--
<?php
if(isset($_POST['submit'])){
echo $_POST['sms']; //This line prints nothing
}
My HTML code--
<form action="" method="POST">
<textarea disabled name="sms" id="sms">
<?php echo $value; //Here the value of textarea and it shows on it?>
</textarea>
<input type="submit" name="submit"/>
</form>
When i want to validate it through values of it, I get empty.
Why this is happen???
Need help!!
Disabled fields are not posted to the server. Readonly fields are posted, so if you really need the contents of the field you could change it to be readonly instead of disabled.
e.g. instead of
<textarea name="sms" id="sms" disabled>
try
<textarea name="sms" id="sms" readonly>

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>

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