将数据从表单发布到另一个页面

时间:2019-12-04 21:38:09

标签: node.js express

Here is my github

我正在尝试在另一页上显示表单中的数据。尝试了多种功能,但仍然一无所获。有什么想法吗? 我还包括了用于创建新帖子的当前功能。

<form action="/bills/online" method="POST" autocomplete="off">
    <label>Name of Service:
        <input type="text" name="name">
    </label><br>
    <label>Bill Category
        <select name="category">
            <option value="Online">Online Subscriptions</option>
            <option value="Utilities">Utilities</option>
            <option value="Other">Other</option>
        </select>
    </label><br>
    <label>Cost per month: $
        <input type="text" name="price">
    </label><br>
    <label>Date due:
        <input type="date" name="dueDate" checked>
    </label><br>
    <input type="submit" value="Add Bill">
</form>


function create(req, res) {
    var bill = new Bill(req.body);
    bill.save(function(err) {
        if (err) return res.render('bills/new');
        console.log(bill);
        res.redirect('/bills/online');
    });
}

0 个答案:

没有答案
相关问题