Back End Development and APIs Projects - Exercise Tracker - Bad form naming practices

This is not so much asking or help as it is pointing out an error in your code.

You have the HTML form name of “exercise-form” with an input name as “:_id” which is probably just copy and pasted from the parameter url. You can’t access this from req.body.:_id because ‘:’ will throw an error. It’s something that may confuse people when they can access it from req.body and took me a few minutes of trial and error to figure out. Unless you meant for this to be an issue to teach us quality assurance practices.


It’s this form in the index.html of the exercise

as you can see the id input name is ‘:_id’ which throws an error if you try to get it from req.body

<form id="exercise-form" method="post">
>         <h3>Add exercises</h3>
>         <p><code>POST /api/users/:_id/exercises</code></p>
>         <input id="uid" type="text" name=":_id" placeholder=":_id" />
>         <input id="desc" type="text" name="description" placeholder="description*" />
>         <input id="dur" type="text" name="duration" placeholder="duration* (mins.)" />
>         <input id="date" type="text" name="date" placeholder="date (yyyy-mm-dd)" />
>         <input type="submit" value="Submit" />
>       </form> here

It is an odd value but you can still get it from the body if you use the value as a string.

console.log('req.body', req.body[':_id'])

But the test doesn’t use the form so you get it from param

console.log('req.params', req.params['_id'])

I’m guessing the name might have been chosen to look like the param value.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.