laravel 中另一个表格内的第二个独立表格
Second independant form inside another form in laravel
我正在尝试做一些我不确定是否可能以及具体如何发生的事情。
我要的是里面有一个table形式和一个加法形式。取决于我点击哪个按钮在控制器中执行不同的操作。这是我目前所拥有的
我的blade
{{ Form::open(array('url' => 'admin/inv')) }}
{{ Form::open(array('url' => 'admin/inv/multiPC')) }}
<table class="table table-bordered">
<tbody>
<tr>
<td><input type="checkbox" name="delete[]" value="{{ $product->product_id }}"> </td>
<td><strong>${{ $product->price }}</strong><input type="number" name='price[]' class="form-control"/></td>
</tr>
</tbody>
</table>
<button type="submit" href="{{ URL::to('/admin/del') }}?_token={{ csrf_token() }}">Delete</button>
<button type="submit" href="{{ URL::to('/admin/multiPC') }}?_token={{ csrf_token() }}">Update Price</button>
{{ Form::close() }}
{{ Form::close() }}
这些都是函数
public function pDelete() {
$delete = Input::only('delete')['delete'];
$pDel = Product::whereIn('product_id', $delete)->delete();
return Redirect::to('/admin/inv')->with('message', 'Product(s) deleted.');
}
public function priceUpdate() {
$pchanges->price = Input::only('price')['price'];
$pChange = Product::whereIn('product_id', $pchanges);
$pChange->save();
return Redirect::to('/admin/inv')->with('message', 'Product(s) price changed.');
}
和路线
Route::post('/admin/inv', ['uses' => 'AdminController@pDelete', 'before' => 'csrf|admin']);
Route::post ('/admin/inv/multiPC', ['uses' => 'AdminController@priceUpdate', 'before' => 'csrf|admin'])
当我检查产品并点击 Delete
按钮产品被删除时会发生什么。但是,当我在价格输入字段中输入价格并点击 Update Price
页面时,页面只会刷新并且价格不会改变。
有没有不用 JS 实现的方法?
尝试这种方法
<form method="POST" class="form-horizontal" action="myapplication/personal">
<input type="number" name='price[]' class="form-control"/>
<input type="checkbox" name="delete[]" value="{{ $product->product_id }}">
<button type="submit" name="step[0]" value="Delete">Delete</button>
<button type="submit" name="step[1]" value="Update">Update Price</button>
</form>
从你的控制器检查步骤的值,然后按你喜欢的方式做
public function formProcess() {
$action = request::get('step'); // i forgot laravel 4 syntex. used laravel 5 instead here :D
if($action == 'Delete')
{
// do delete operation
}
else
{
//do update operation
}
}
希望这对您有所帮助
我正在尝试做一些我不确定是否可能以及具体如何发生的事情。
我要的是里面有一个table形式和一个加法形式。取决于我点击哪个按钮在控制器中执行不同的操作。这是我目前所拥有的
我的blade
{{ Form::open(array('url' => 'admin/inv')) }}
{{ Form::open(array('url' => 'admin/inv/multiPC')) }}
<table class="table table-bordered">
<tbody>
<tr>
<td><input type="checkbox" name="delete[]" value="{{ $product->product_id }}"> </td>
<td><strong>${{ $product->price }}</strong><input type="number" name='price[]' class="form-control"/></td>
</tr>
</tbody>
</table>
<button type="submit" href="{{ URL::to('/admin/del') }}?_token={{ csrf_token() }}">Delete</button>
<button type="submit" href="{{ URL::to('/admin/multiPC') }}?_token={{ csrf_token() }}">Update Price</button>
{{ Form::close() }}
{{ Form::close() }}
这些都是函数
public function pDelete() {
$delete = Input::only('delete')['delete'];
$pDel = Product::whereIn('product_id', $delete)->delete();
return Redirect::to('/admin/inv')->with('message', 'Product(s) deleted.');
}
public function priceUpdate() {
$pchanges->price = Input::only('price')['price'];
$pChange = Product::whereIn('product_id', $pchanges);
$pChange->save();
return Redirect::to('/admin/inv')->with('message', 'Product(s) price changed.');
}
和路线
Route::post('/admin/inv', ['uses' => 'AdminController@pDelete', 'before' => 'csrf|admin']);
Route::post ('/admin/inv/multiPC', ['uses' => 'AdminController@priceUpdate', 'before' => 'csrf|admin'])
当我检查产品并点击 Delete
按钮产品被删除时会发生什么。但是,当我在价格输入字段中输入价格并点击 Update Price
页面时,页面只会刷新并且价格不会改变。
有没有不用 JS 实现的方法?
尝试这种方法
<form method="POST" class="form-horizontal" action="myapplication/personal">
<input type="number" name='price[]' class="form-control"/>
<input type="checkbox" name="delete[]" value="{{ $product->product_id }}">
<button type="submit" name="step[0]" value="Delete">Delete</button>
<button type="submit" name="step[1]" value="Update">Update Price</button>
</form>
从你的控制器检查步骤的值,然后按你喜欢的方式做
public function formProcess() {
$action = request::get('step'); // i forgot laravel 4 syntex. used laravel 5 instead here :D
if($action == 'Delete')
{
// do delete operation
}
else
{
//do update operation
}
}
希望这对您有所帮助