How to Retrieve Data From a Textarea with PHP 


               


How to Retrieve Data From a Textarea with PHP



PHP


In this tutorial, we will go over how to retrieve data from a textarea using PHP. '

Textareas, also called multi-line text input, are used pretty extensively in forms to extract information from a user. Unlike text boxes, textareas span multiple lines, so that a user can enter into lines of information, rather than just one single line. Therefore, textareas can accomodate more words or sentences.

As an example, below is a textarea in HTML which is very common in forms on the web, such as when a user needs to enter in multiple lines of text:





The comment that you entered is:





PHP allows us to extract the data from this input text area to do whatever we want to accomplish with the data.

Coding

HTML Code

This is the HTML code to create the Additional Comments multi-line text input.



PHP Code

This is the PHP code to retrieve the data entered into the textarea.



The code to then output the line beneath the textarea which a user has entered is:



The reason these 2 pieces of PHP code have to broken up is because PHP retrieval of an HTML form element must be done before the HTML form element. Therefore, the code to retrieve the data from the textarea, which is $comments= $_POST['comments']; must come before the HTML text area. With the retrieval done before, we can now output the retrieved data after the HTML element.

The superglobal aray $_POST retrieves all which is written in the multi-line text input form and stores it in the $comments variable. The echo statement then prints out the comment which is written in this field.

Related Resources

How to Retrieve Data from a Text Box with PHP

How to Retrieve Data from a Radio Button with PHP

How to Retrieve Data from a Check box with PHP

How to Retrieve Data from an Array of Checkboxes with PHP

How to Retrieve Data from a Drop-down List with PHP

How to Retrieve Data from a List Box with PHP




HTML Comment Box is loading comments...