我正在使用表单从列表中捕获信息并将其保存到数据库中的新表中。当餐馆名称不止一个单词,即纽约时,它会忽略第一个单词后只将第一个单词添加到数据库中的所有内容。有办法解决这个问题吗?
查看:
{{#allRestaurantsData}}
<div class="listing">
<form action="/restaurants" method="post">
<h2> {{restaurant.name}}
<input type="image" src="../wishlisticon.png" />
</h2>
<img id="image" src="{{restaurant.featured_image}}" width='500' height='300' alt="picture unavailable">
<ul>
<li>Address :{{ restaurant.location.address}}</li>
<li> {{restaurant.location.locality}}</li>
<li>{{restaurant.location.city}}</li>
<li>{{restaurant.location.zip}}</li>
</ul>
<div id="comments">
</div>
<input type="hidden" name="restaurant_id" value={{restaurant.id}}>
<input type="hidden" name="restaurant_name" value={{restaurant.name}}>
<input type="hidden" name="restaurant_city" value={{restaurant.location.city}}>
</form>
</div>
{{/allRestaurantsData}}
控制器:
router.post("/restaurants", restaurantsModel.create, (req, res, next) => {
console.log("Hitting /restaurants", res.locals.listitem);
});
型号:
restaurantsModel.create = (req, res, next) => {
console.log("from restaurants.Model", req.body);
db
.manyOrNone(
"INSERT INTO restaurants (res_id, name, city) VALUES ($1, $2, $3) RETURNING *;",
[
req.body.restaurant_id,
req.body.restaurant_name,
req.body.restaurant_city
]
)
答案 0 :(得分:0)
经过大量的试验错误后,我找到了答案。我将添加的引号更改为以下两行中的值输入。
<input type="hidden" name="restaurant_name" value="{{restaurant.name}}" >
<input type="hidden" name="restaurant_city" value="{{restaurant.location.city}}">