Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php $_POST method to get textarea value

Tags:

post

php

I am using php to get textarea value using post method but getting a weird result with that let me show you my code

<form method="post" action="index.php">
    <textarea id="contact_list" name="contact_list"></textarea>
    <input type="submit" name="submit" value="Send" id="submit"/>
</form>

I am entering some names and their email address in the textarea, and everytime i echo the value or textarea it skips the email address and only showing the name let me show the way i am entering value in textarea

"name1" <[email protected]>, "name2" <[email protected]> 

and once I will echo using php it will only echo the name and will skip the email address.

like image 442
Frank Avatar asked Sep 28 '11 11:09

Frank


People also ask

How get data from textarea from database in PHP?

Code is supposed to get users nickname and input message, store both in database and retrieve it back to text area, smth similar to one man chat (whatever is typed after clicking 'Send message' should be stored to database and retrieved and shown in the text area).

Can we use value attribute in textarea?

<textarea> does not support the value attribute.

How do I display textarea content in HTML?

Use the <textarea> tag to show a text area. The HTML <textarea> tag is used within a form to declare a textarea element - a control that allows the user to input text over multiple rows. Specifies that on page load the text area should automatically get focus.

What is textarea PHP?

Definition and Usage. The <textarea> tag defines a multi-line text input control. The <textarea> element is often used in a form, to collect user inputs like comments or reviews. A text area can hold an unlimited number of characters, and the text renders in a fixed-width font (usually Courier).


2 Answers

Always (always, always, I'm not kidding) use htmlspecialchars():

echo htmlspecialchars($_POST['contact_list']);
like image 68
Tomalak Avatar answered Sep 22 '22 09:09

Tomalak


Make sure your escaping the HTML characters

E.g.

// Always check an input variable is set before you use it
if (isset($_POST['contact_list'])) {
    // Escape any html characters
    echo htmlentities($_POST['contact_list']);
}

This would occur because of the angle brackets and the browser thinking they are tags.

See: http://php.net/manual/en/function.htmlentities.php

like image 41
Petah Avatar answered Sep 18 '22 09:09

Petah