复选框已选中并插入到数据库中
Checkbox checked and inserted into database
我正在尝试根据复选框将数据保存到数据库中。如果复选框被选中则保存,否则不保存。我的想法是将 ng-model 值传递给 php 值,然后进行验证,但它不起作用。
blade.php
<input type="checkbox" name="update_info" ng-model="item.update_info"></label>
php
$value = "{{item.update_info}}"
if ($vendor === NULL && $value === true) {
try {
DB::table('vendors')
->insert([
'vendor_id' => $vendor_id,
'price' => $price
]);
} catch(PDOException $e) {
throw new TransactionException([$e->getMessage()]);
}
}
checkbox的值不是boolean类型true,而是一个字符串,值为'on';
试试这个:
if ($vendor === NULL && $value === 'on') {
您在复选框中使用值,当它被选中时,该值将转到服务器,例如:
<input type="checkbox" name="update_info" ng-model="item.update_info" value="1"></label>
所以你可以在服务器中验证
$value = Input::get('update_info');
if($value){ ... }
试试这个,让我知道它是如何工作的:)
我正在尝试根据复选框将数据保存到数据库中。如果复选框被选中则保存,否则不保存。我的想法是将 ng-model 值传递给 php 值,然后进行验证,但它不起作用。
blade.php
<input type="checkbox" name="update_info" ng-model="item.update_info"></label>
php
$value = "{{item.update_info}}"
if ($vendor === NULL && $value === true) {
try {
DB::table('vendors')
->insert([
'vendor_id' => $vendor_id,
'price' => $price
]);
} catch(PDOException $e) {
throw new TransactionException([$e->getMessage()]);
}
}
checkbox的值不是boolean类型true,而是一个字符串,值为'on';
试试这个:
if ($vendor === NULL && $value === 'on') {
您在复选框中使用值,当它被选中时,该值将转到服务器,例如:
<input type="checkbox" name="update_info" ng-model="item.update_info" value="1"></label>
所以你可以在服务器中验证
$value = Input::get('update_info');
if($value){ ... }
试试这个,让我知道它是如何工作的:)