[英]LARAVEL: how to send data from view to controller
I need to send a value of <input type='CHIPS'>
我需要发送
<input type='CHIPS'>
from add.blade.php to userController@add.php 从add.blade.php到userController@add.php
this is the code of add.blade.php file: 这是add.blade.php文件的代码:
<div class="container">
<form method="POST" action="{!! url('add') !!}" id="ajouter" accept-charset="UTF-8">
<label for="nom">Entrez votre nom : </label>
<input name="name" type="text" id="name">
<input name="email" type="email" id="email">
<input name="password" type="password" id="password">
<label for="permution">saisier les parmutions : </label>
<div class="chips" name="permution"></div>
<input class="btn-info" type="submit" value="Envoyer !">
<div id="permution" name="permution">
</div>
</form>
</div>
and this is the scripte in add.blade.php file : where i got data from chips_form and I set them in a new value of type String 这是add.blade.php文件scripte:我来自哪里chips_form得到的数据和我将它们设置在一个String类型的新值
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="css/materialize/js/materialize.min.js"></script>
<script>
$(function() {
var data = $('.chips').material_chip();
var dataString = JSON.stringify(data);
});
</script>
route.php file : route.php文件 :
Route::get('/add', 'UsersController@add_form');
Route::post('/add', 'UsersController@add');
userController.php file : userController.php文件:
public function add_form()
{
return view('add');
}
public function add(Request $request)
{
$name = $request->input('name');
$email=$request->input('email');
$password = $request->input('password');
$cryptPassword= bcrypt($password);
//Insert SQL Request
}
To send the contenct of dataString to the controller, you can create a hidden input in the form, and set its value using jQuery. 要将dataString的内容发送给控制器,您可以在表单中创建一个隐藏的输入,并使用jQuery设置其值。
First, add an input to the form: 首先,向表单添加输入:
<input id="ichips" type="hidden" name="chips">
Then, set its value using jQuery: 然后,使用jQuery设置其值:
var data = $('.chips').material_chip();
var dataString = JSON.stringify(data);
$("#ichips").val(dataString);
When the user send the form, the value will be in the hidden input. 当用户发送表单时,该值将在隐藏的输入中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.