$ _POST is empty after submitting the form

I use Twitter Bootstrap to build a web application. I have a form where the user must enter his first and last name and click "Submit." The problem is that it $_POSTreturns empty. I am using WAMP for Windows 8.

<?php
if(isset($_POST["send"])) {
    print_r($_POST)
} else {
    ?>
    <form class="form-horizontal" action="" method="post">
        <div class="control-group"> <!-- Firstname -->
            <label class="control-label" for="inputEmail">First name</label>
            <div class="controls">
                <input type="text" id="inputName" placeholder="First name">
            </div>
        </div>
        <div class="control-group"> <!-- Lastname -->
            <label class="control-label" for="inputEmail">last name</label>
            <div class="controls">
                <input type="text" id="inputLastname" placeholder="Last name">
            </div>
        </div>
        <div class="form-actions">
            <button type="submit" name="send" class="btn btn-primary">Submit data</button>
            <a href="<?php $mywebpage->goback(); ?>" class="btn">Cancel</a>
        </div>
    </form>
    <?php
}
?>

Thanks in advance

+5
source share
6 answers

Try plz and add names to input types like

<input type="text" id="inputLastname" name="inputLastname" placeholder="Last name">

Now check the $ _POST variable.

+20
source

Your entries have no attributes name. Set these options:

<input type="text" id="inputName" placeholder="First name" name="first_name" />
<input type="text" id="inputLastname" placeholder="Last name" name="last_name" >

Also, see how you detect form submission:

if(isset($_POST['send']))

, . , Internet Explorer , .

:

if($_SERVER['REQUEST_METHOD'] == 'POST')

if(isset($_POST['first_name'], $_POST['last_name']))

- Why isset($_POST['submit']) .

+6
<?php
if(isset($_POST["send"])) {
  echo $_POST["inputName"];
    echo $_POST["inputLastname"];
} 
else {
    ?>
    <form class="form-horizontal" action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST">
        <div class="control-group"> <!-- Firstname -->
            <label class="control-label" for="inputEmail">First name</label>
            <div class="controls">
                <input type="text" id="inputName" placeholder="First name" name="inputName"> 
            </div>
        </div>
        <div class="control-group"> <!-- Lastname -->
            <label class="control-label" for="inputEmail">last name</label>
            <div class="controls">
                <input type="text" id="inputLastname" name="inputLastname" placeholder="Last name">
            </div>
        </div>
        <div class="form-actions">
            <input type="submit" name="send" class="btn btn-primary">Submit data</button>
            <a href="#" class="btn">Cancel</a>
        </div>
    </form>
    <?php
}
?>
+1

, , $_POST['send'], . "" - , , $_POST.

, .

0

I noticed that using the name attribute does not work with Validator for (if (isset ($ _ POST ["send"])). If you want to add confirmation to your form, I recommend that you follow this path!

Decision

<button type="submit" class="btn btn-primary">Submit data</button>

Php

if($_SERVER['REQUEST_METHOD'] == 'POST')
0
source

Add the file location to the action or use:

<form class="form-horizontal" action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
-2
source

All Articles