Posted on 2006-03-20
Last Modified: 2010-08-05

I have a simple
<TEXTAREA NAME="comment" ROWS=6 COLS=40></TEXTAREA> within a form..
I would like to do is basically have any text typed into the text area echoed to the next page once the submit button is clicked...
I have no idea on how to do this..

Any help would be greatful..
Question by:greeneel
    LVL 15

    Expert Comment

    In the code for the page that form is being submitted to, use:

    echo $_POST['comment'];
    LVL 49

    Accepted Solution

    You can use this:

    if($_SERVER['REQUEST_METHOD'] == 'POST') {
      echo 'Comment: ';
      echo htmlspecialchars($_POST['comment']);

    LVL 6

    Expert Comment

    echo $_REQUEST["comment"];

    There you go 3 answers.
    Tomeeboy assumes you used the post method to submit your form.
    Roonaan, assumes that too, but checks first.

    If you use $_REQUEST it will get a POST or GET form variable.
    LVL 49

    Expert Comment

    $_REQUEST will actually also get $_COOKIE variables, brian ;-)

    LVL 15

    Expert Comment

    Better to do it right to begin with, rather than compensate for the wrong method :)
    LVL 17

    Expert Comment

    I seriously, seriously doubt somebody would put textarea contents into $_GET.
    Setting a Cookie is just as unlikely.
    $_POST is the only Logical one.

    But $_REQUEST should work for any case, unless it is being rewritten somewhere.
    LVL 1

    Expert Comment

    Everybody here answers the question... I'll just complement all of them.

    Use lowercase HTML tags... and prefer to stylish things, not delivering to HTML this job.

    You simple HTML code should be something like:

    <textarea name="comment" style="width: 200px; height: 100px;"></textarea>

    Even if you are building a simple script, you must have security in your mind. Imagine how many headaches will you have if you do not bother too much with security... even if you are a new programmer in the language, try to learn security techniques.
    I think a good one to apply in your script is to htmlentities the user comment. Htmlentities is a function that converts any found chars that has another notation in HTML entity to its one. Good... but it supports a second argument that converts quotes, and I highly suggest you to use it.

    so, the right way to output the send code is this:

        echo htmlentities($_POST['comment'], ENT_QUOTES);

    Just put this sentence in your mind and try to follow it everytime: "Filter input, Escape output!"

    I hope this helps...

    LVL 11

    Author Comment

    Thanks guys..


    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now