Text areas act like multi-line text fields, and you create them with the HTML <TEXTAREA> element. You can see an example, phptextarea.html, in Example 5-3, where we're asking the user to list his or her friends in a text area named "Friends". When the user clicks the Submit button here, that data will be sent to a PHP script, phptextarea.php, and we'll echo that data in a new web page. Example 5-3. A text area, phptextarea.html<HTML> <HEAD> <TITLE>Using Text Areas</TITLE> </HEAD> <BODY> <CENTER> <H1>Using Text Areas</H1> <FORM METHOD="POST" ACTION="phptextarea.php"> Please list your best friends: <BR> <TEXTAREA NAME="Friends" COLS="50" ROWS="5"> 1. 2. 3. 4. </TEXTAREA> <BR> <BR> <INPUT TYPE="SUBMIT"> </FORM> </CENTER> <BODY> </HTML> This web page, textarea.html, appears in Figure 5-3, with some user data. Figure 5-3. Using a text area.To recover data from the text area in the PHP script phptextarea.php, you can use $_REQUEST["Friends"], as you see in Example 5-4. Example 5-4. A text area, phptextarea.php<HTML> <HEAD> <TITLE> Using Text Areas </TITLE> </HEAD> <BODY> <CENTER> <H1> Retrieving Data From Text Areas </H1> Your best friends are: <?php echo $_REQUEST["Friends"]; ?> </CENTER> </BODY> </HTML> You can see the results in Figure 5-4, where we've read the text the user entered into the text area. No problem. Figure 5-4. Reading data from a text area. |