We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Problem with getting POST variables

I have a strange problem with getting POST variables. I'm using bootstrap 3.2, here is my form :

    <div class="col-sm-6" style="margin-left: 25%;">
    <form role="form" action="/home/sign-in" method="post">
        <div class="form-group">
            <label for="exampleInputEmail1">Email address</label>
            <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email">
        </div>
        <div class="form-group">
            <label for="exampleInputPassword1">Password</label>
            <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
        </div>
        <button type="submit" class="btn btn-default">Sign in</button>
    </form>
    </div>

And the action :

    public function signinAction()
    {
        var_dump($_POST);
        var_dump($this->request->getPost());
        exit;
        if (!$this->request->isPost()) {
            return $this->response->redirect('/');
        }

        $usersModel = new Users();

        if (($usersModel->getEmail() == $this->request->getPost('email')) &&
            ($usersModel->getPassword() == $this->request()->getPost('password'))
        ) {
            $this->session->set(array('signin' => true));
            return $this->response->redirect('/admin/dashboard');
        }

        $this->flashSession->error('Email/Password are wrong, please try again!');
    }

When I'm dumping the POST variable there is nothing inside :

    array (size=0)
        empty
    array (size=0)
        empty


125.7k
Accepted
answer

All your input elements need the "name" attribute. Without that attribute, the contents of the element won't be POSTed

edited Dec '14

As @quasipickle pointed out, unless you're doing an AJAX submit of the form and getting the values from another way (eg. JavaScript), the default way to retrieve data fields from sent forms its from their attribute name.

Also, keep in mind that the name must be unique as ids (despite radiobuttons). You can read more about it here.