Open HusJAW opened 2 years ago
We're using the same name
because these are radio buttons, so the idea is that users will be able to select only one of the two buttons and the selected button will give us the value (the button that has not been selected will be ignored by default).
it is allowed to have multiple inputs with the same
name
, onlyid 's
must be unique. I wouldn't recommend it however, why even put yourself in a position to be confused down the road. The name attribute only defines what each form field element will be represented as when sent to the serverconst form = request.body; const recipeType = form.recipe; // 1 Get user id console.log(form[recipeType]); const sid = request.signedCookies.sid; const user = await model.getSession(sid); // 2 Add post await model.addPost(user.id, form.dish, form[recipeType], form.joke);
not sure if
form[recipeType]
is why your app is crashingmaybe add an if check
if(recipeType === recipeURL) { await model.addPost(user.id, form.dish, form.recipeURL , form.joke); }else { await model.addPost(user.id, form.dish, form.recipeSteps , form.joke); }