【发布时间】:2017-03-25 02:38:03
【问题描述】:
这是我的表格,未填写 这是提交的表格 如图所示,第一个表单元素是一个下拉列表(带有选项的选择元素)
这是有问题的表格:
这是选择元素:
<div class="form-group" ng-controller="clubsCtrl">
<select class="form-control" style="margin-top:10px;"
ng-options="club.ID as club.SHORT_NAME for club in clubs"
ng-model="selected_club_id">
</select>
<label>Odaberite klub kojem igrač pripada</label>
<p>TEST : ID za odabrani klub :{{selected_club_id}}</p>
</div>
表单中还有其他元素,例如:
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<input type="text" class="form-control"
id="firstname"
ng-model="firstname">
<label for="firstname">Ime</label>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="text" class="form-control"
id="lastname" ng-model="lastname">
<label for="lastname">Prezime</label>
</div>
</div>
</div>
如您所见,要填充我正在使用的选择元素中的选项
俱乐部控制。我正在显示俱乐部名称,但是一旦单击名称,就会选择 ID。 select下面的标签显示id确实是提取出来的(见第二张图)
这是电话:
class="btn btn-lg btn-primary btn-raised ink-reaction pull-right">
保存
所以你可以看到我正在从 playerCtrl 调用函数 addPlayer() 这是函数:
$scope.addPlayer = function()
{
$http.post('add_player.php',
{
'selected_club_id' : $scope.selected_club_id,
'firstname' : $scope.firstname,
'lastname' : $scope.lastname,
'shirt_number' : $scope.shirt_number,
'position' : $scope.position,
'age' : $scope.age,
'national_team' : $scope.national_team,
'height' : $scope.height,
'weight' : $scope.weight,
'price' : $scope.price,
'ownership' : $scope.ownership,
'datum_rodjenja' : $scope.datum_rodjenja
}
).success(function(data, status, headers, config)
{
infoTime('<b>Success</b>');
});
};
这是add_player.php
<?php
// Including database connections
require_once '../assets/database/config.php';
$data = json_decode(file_get_contents("php://input"));
if (count($data) > 0)
{
// escape_string is just a helper function
$id_team = escape_string($data->selected_club_id);
$firstname = escape_string($data->firstname);
$lastname = escape_string($data->lastname);
$shirt_number = escape_string($data->shirt_number);
$position = escape_string($data->position);
$age = escape_string($data->age);
$national_team = escape_string($data->national_team);
$height = escape_string($data->height);
$weight = escape_string($data->weight);
$price = escape_string($data->price);
$ownership = escape_string($data->ownership);
$datum_rodjenja = escape_string($data->datum_rodjenja);
// query is justa helper function
$query = query("INSERT INTO players(firstname, lastname, id_team, shirt_number, position, age, national_team, height, weight, price, ownership, date_of_birth, id_status) VALUES('{$firstname}','{$lastname}','{$id_team}','{$shirt_number}','{$position}','{$age}','{$national_team}','{$height}','{$weight}','{$price}','{$ownership}','{$datum_rodjenja}', '1')");
$insert_result = confirm($query); // confirm = helper function
# JSON-encode the response
echo $json_response = json_encode($insert_result);
}
?>
结果:所有东西都被正确插入,除了 $id_team, 我从元素中得到的值
我尝试了很多东西,似乎没有任何效果。如果有人有任何提示或建议,请帮助。
感谢您的所有 cmets 和建议。 对不起,我的英语不好 埃迪斯
【问题讨论】:
-
抱歉,我的图片好像没有正确上传:(
-
表格,未填写:imgur.com/XDrsYBn
-
表格,填写完毕imgur.com/lFT2ADD
-
再次抱歉,忘记显示相关表单:
-
你试过检查生成的选择吗?
标签: php angularjs forms select post