sameold
sameold

Reputation: 19242

Why this form submit isn't working as expected

I have this code in test.php.

For some reason, even when I click submit, I don't get the message that it's posting. Anyone can explain why? and how can I get it to work.

<body>
    <form action="" method="post">
        <input type="text" id="inp" />
        <input type="submit" value="submit" />      
    </form>

    <?php
    if (isset($_POST['submit'])) {
        echo "posting";
    }

    ?>
</body>

Upvotes: 0

Views: 315

Answers (3)

Mikk
Mikk

Reputation: 2229

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    echo "posting";
}

Upvotes: 1

Ameer
Ameer

Reputation: 771

Try this:

<body>
    <form action="" method="post">
        <input type="text" id="inp" />
<input type='hidden' name='submit' value=''>
        <input type="submit" value="submit" />      
    </form>

    <?php
    if (isset($_POST['submit'])) {
        echo "posting";
    }

    ?>
</body>

Upvotes: 0

tttony
tttony

Reputation: 5082

Give a name to the input:

<input type="submit" name="submit" value="submit" /> 

Upvotes: 3

Related Questions