我需要在提交表单并使用laravel将数据插入db后显示成功消息。
主要的想法是,在提交表单后,我将数据插入到数据库中,之后我显示插入成功的消息
表格如下:
<div class = "draggable">
<form class="popupForm" method ="post" id = "popupForm" onsubmit="return insertAddonCategorie();">
<table align="center" cellpadding = "10">
<tr>
<td colspan="2" align="center">
Create new Category for Addons
</td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" id="newAddonCategoryName" name="category_name" maxlength="30"/>
</td>
</tr>
<tr>
<td>Minimum</td>
<td>
<input type="number" name="min_addons" id="newAddonCategoryMin" />
</td>
</tr>
<tr>
<td>Maximum</td>
<td><input type="number" name="max_addons" id="newAddonCategoryMax" /></td>
</tr>
<tr>
<td>Required</td>
<td><input type="checkbox" name="required" value="Required" id ="newAddonCategoryRequired"></td>
</tr>
<input type="hidden" name="action" value="insert"/>
<input type="hidden" name="isMandatory" value="" id="categoryMandatoryField"/>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Create" id = "buttonCreate">
<input type="reset" value="Cancel" onclick = 'hidepopup()'>
</td>
</tr>
</table>
</form>
</div>
insertAddonCategorie()只检查是否填充了所有字段并返回true。
控制器插入中的如下所示:
private function insertAction(Request $request){
$user = Auth::user();
$restaurant_owner_id = $user->restaurant_id;
$category_name = $request->input('category_name');
$max_addons = $request->input('max_addons');
$min_addons = $request->input('min_addons');
$isMandatory = $request->input('isMandatory');
$item_status = 1;
DB::table('addon_category')
->insert(['category_name'=>$category_name,
'max_addons'=>$max_addons,
'min_addons'=>$min_addons,
'isMandatory'=>$isMandatory,
'addon_category_status'=>$item_status,
'restaurant_id'=>$restaurant_owner_id]);
}
答案 0 :(得分:0)
在html中为show message添加此代码
addId = new RequestQueue();
在控制器中添加此代码
addId.add(request);