Php $_POST method to get textarea value

前端 未结 8 1254
一整个雨季
一整个雨季 2021-02-01 08:45

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

相关标签:
8条回答
  • 2021-02-01 09:24

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

    echo htmlspecialchars($_POST['contact_list']);
    
    0 讨论(0)
  • 2021-02-01 09:25

    Try this:

    <?php /* the php */ ?>
    <?php 
        if ($_POST['submit']) {
            // must work
            echo $_POST['contact_list'];
        };
    ?>
    
    
     <?php /* and the html */ ?>
    
    <!doctype html>
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>teszt</title>
        </head>
        <body>
            <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
                <textarea id="contact_list" name="contact_list"></textarea>
                <input type="submit" name="submit" value="Send" id="submit"/>
            </form>
        </body>
    </html>
    
    0 讨论(0)
  • 2021-02-01 09:26

    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

    0 讨论(0)
  • 2021-02-01 09:37
    //My Form
    <form id="someform">
            <div class="input-group">
                <textarea placeholder="Post your Comment Here ..." name="post" class="form-control custom-control" rows="3" style="resize:none"></textarea> 
                <span class="input-group-addon">                                            
                    <button type="submit" name="post_comment" class="btn btn-primary">
                        Post
                    </button>
                </span>
            </div>
        </form>
    
    //your text area get value to URL
    <?php
            if(isset($_POST['post_comment']))
            {
                echo htmlspecialchars($_POST['post']);
            }
    
        ?>
    
    //print the value using get
    echo $_GET['post'];
    
    //url must be like this
    http://localhost/blog/home.php?post=asdasdsad&post_comment=
    
    //post value has asdasdsad so it will print to your page
    
    0 讨论(0)
  • 2021-02-01 09:41

    Remove some of your textarea class like

    <textarea name="Address" rows="3" class="input-text full-width" placeholder="Your Address" ></textarea>
    

    To

    <textarea name="Address" rows="3" class="full-width" placeholder="Your Address" ></textarea>
    

    It's dependent on your template (Purchased Template). The developer has included some JavaScript to get the value from correct object on UI, but class like input-text just finds only $('input[type=text]'), that's why.

    0 讨论(0)
  • 2021-02-01 09:41

    it is very simply. Just write your php value code between textarea tag.

    <textarea id="contact_list"> <?php echo isset($_POST['contact_list']) ? $_POST['contact_list'] : '' ; ?> </textarea>
    
    0 讨论(0)
提交回复
热议问题