phpfilter-input

filter_input textarea not working


I am new using filter_input. At least it works fine with normal form fields however when I try with a text area then it returns false.

Textarea:

<textarea cols="50" rows="10" name="message" id="message"></textarea>

Below here you see the code I use.

filter_input_array(INPUT_POST, "message", FILTER_DEFAULT);

This returns:

filter_input or filter_input_array = bool(false);
$_POST["message"] = "message";

However if I just use $_POST["message"] it works fine. But here I get a warning from netbeans. So I'de like to use another way to get it.


Solution

  • Try this...

    <?php
    if(isset($_POST['message'])){
        $message = filter_input(INPUT_POST, "message", FILTER_DEFAULT);
        echo $message;
    }
    ?>
    <form action="" method="POST">
      <textarea cols="50" rows="10" name="message" id="message"></textarea>
      <input type="submit" value="submit">
    </form>
    

    To know more about PHP Filter visit here