Beau
Beau

Reputation: 1771

POST request variables not coming through in Sails.js

I'm new to Sails, so I may be doing this wrong, but I can't seem to get data from my form in the controller.

The submit action routes to the proper controller method.

<form action="/create" method="POST">
  <div class="form-group">
    <label for="title">Title</label>
    <input type="text" class="form-control" id="title">
  </div>
  <button type="submit" class="btn btn-default">Submit</button>
</form>

Controller action:

save: function (req, res) {
    console.log(req.param('title'));
    console.log(req.params.all());
}

Results in:

undefined
{}

How am I supposed to get the submitted form data?

Upvotes: 1

Views: 526

Answers (1)

Luca Colonnello
Luca Colonnello

Reputation: 1456

It seems that you omit the name attribute.

    <label for="title">Title</label>
    <input type="text" class="form-control" id="title" name="title">

Without this the parameter can't be received from the server.

Upvotes: 4

Related Questions