Reputation: 5
I have a jade template that I have a create user section that adds a user to an orchestrate.io database. Below that I have a list of all users with a delete and update link. The delete works fine by passing the key through the URL as res.params.id when it gets to the server. When I update using the key it does not see the new values from the input fields so I don't get a payload value to use on the server side. How can I update this field? Here is my code: Server side -
server.route({
method: 'GET',
path: '/update/{id}',
handler: function(req, reply){
db.put('users', req.params.id, {
"name": 'name',
"password": 'password',
"email": 'email'
})
.then(function (result) {
reply.redirect('/');
})
.fail(function (err) {
reply('no update');
});
}
});
Jade Template-
doctype html
html
head
title Last October Weekly Challenge
body
div.container
p This is the main user page. You can create, update, delete and view users.
form(action='/',method='POST')
label(for='name') Name
input(id='name',type='text',value='',placeholder='Enter Name',name='name')
label(for='password') Password
input(id='password',type='password',value='',placeholder='Enter Password',name='password')
label(for='email') Email
input(id='email',type='email',value='',placeholder='Enter Email',name='email')
input(id='submit',type='submit',value='Create User',name='submit')
p Here are the current users:
table
each item in items
tr
td
input(type='text' name='update-name' value= item.value.name)
td
input(type='text' name='update-password' value= item.value.password)
td
input(type='email' name='update-email' value= item.value.email)
td
a(href="/delete/" + item.path.key) Delete
td
a(href="/update/" + item.path.key) Update
Thank you for helping.
Upvotes: 0
Views: 120
Reputation: 11
I see a couple of things that could cause your issue. 1) Your server.route method is "GET" but it should be "POST" to handle/match the form's method attribute; and, 2) You don't have the ID as a hidden field in the form (or as part of the action's URL e.g. form action="/update/12345" method="POST"...).
Upvotes: 0