我需要两个提交按钮来更新表单,
当前,当我点击“提交”时,它保存了我的数据并重定向到另一个页面,我可以在其中编辑多张图像(所以我的表单就像两步函数一样)
我想添加另一个按钮以仅保存我的数据并返回索引页面(跳过第二步)
最后的结果将是带有两个按钮的编辑表单
controller function
public function update(Request $request, $id)
{
// validation and....
$product->save();
// this is my current button action (redirect to second step)
return redirect()->route('editmultiimages',
$product->id)->with('success',
'Product, '. $product->title.' updated, now you can edit images.');
// need second button action here
}
blade form
{{ Form::model($product, array('route' => array('products.update', $product->id), 'method' => 'PUT', 'files' => true)) }}
// my inputs
// my current button (saves data and goes to next step)
{{ Form::submit('Edit Images', array('class' => 'btn btn-success')) }}
{{Form::close()}}
有什么主意吗?
答案 0 :(得分:0)
您可以使用两个具有不同值属性的提交按钮。
查看:
...
{{ Form::submit('Edit Images', array('class' => 'btn btn-success','name'=>'btnSubmit', 'value'=>'button1')) }}
{{ Form::submit('Edit Images', array('class' => 'btn btn-success','name'=>'btnSubmit', 'value'=>'button2')) }}
...
控制器:
public function update(Request request) {
if(request->get('btnSubmit') == 'button1') {
// do your stuff here...
} else if(request->get('btnSubmit') == 'button2') {
// do your stuff here...
}
}
答案 1 :(得分:0)
blade form
{{ Form::submit('Edit Images', array('class' => 'btn btn-info', 'name' => 'submitbutton')) }}
{{ Form::submit('Finish', array('class' => 'btn btn-success', 'name' => 'submitbutton')) }}
controller
switch ($request->submitbutton) {
case 'Edit Images':
return redirect()->route('editmultiimages', $product->id)->with('success', 'Product, '. $product->title.' updated, now you can edit images.');
break;
case 'Finish':
Session::flash('success', 'Product, '. $product->title.' updated successfully.');
return redirect()->route('products.index', $product->id);
break;
}
希望它可以帮助别人。
答案 2 :(得分:0)
您可以对提交按钮使用相同的名称和不同的值属性
//示例:
switch($request->submitbutton) {
case 'save and close':
//action save here and close
break;
case 'save and new':
//action for save and new
break;
case 'save and search':
//action for save and search
break;
case 'apply':
//action for save and route here
break;
}
//控制器:
if ($request->submitbutton == 'apply') {
return redirect()->route('admin.products.edit', $product->id)->with('success', "new product {$product->name} created as well.");
} else if ($request->submitbutton == 'save and search'){
return redirect()->route('admin.products.index', ['name' => $product->name])->with('success', "product {$product->name} saved.");
} else if ($request->submitbutton == 'save and close'){
return redirect()->route('admin.products.index')->with('info', "product {$product->name} saved");
} else if ($request->submitbutton == 'save and new'){
return redirect()->route('admin.products.create' , $request->category_id)->with('info', "product {$product->name} saved.");
}
或
df = df.sort_values(['location','dates']).set_index('dates')
df['SUM2D'] = df.groupby('location')['T'].rolling(window=2, freq='D').sum().values
df[::-1]