HTML:
<form id="reg" name="reg" enctype="application/x-www-form-urlencoded" action="http://api.phphotspot.com/v-2/client-register" method="post">
<md-input-container class="md-block">
<label for="country">Country</label>
<md-select name="country" ng-model-options="{trackBy: '$value.id'}" id="country" ng-model="signupFormData.country" placeholder="Select a Country">
<md-option ng-value="opt" ng-repeat="opt in countries">{{opt.name}}</md-option >
</md-select>
</md-input-container>
<md-button ng-submit class="md-raised md-primary">Register</md-button>
</form>
JS:
<script>
angular.module('signUpNewUser', ['ngMaterial'])
.controller('signUpFormController', function($scope) {
$scope.signupFormData = {};
$scope.countries = [
{id:"AU", name:"Australia"},
{id:"BR", name:"Brazil"},
{id:"CA", name:"Canada"},
{id:"IT", name:"Italy"},
{id:"GB", name:"United Kingdom"},
{id:"US", name:"United States"}];
});
</script>
我想在用户单击按钮时提交所选国家/地区。例如,当用户选择国家澳大利亚并提交时,在服务器端 $_POST['country']
应该等于 "AU"。但目前 $_POST['country']
变成字符串 "Object" 而不是 "AU"。
有人可以帮我解决这个问题吗?
我将 html 更改为,
<form id="reg" name="reg" enctype="application/x-www-form-urlencoded" action="http://api.phphotspot.com/v-2/client-register" method="post">
<md-input-container class="md-block">
<label for="country">Country</label>
<md-select name="country" ng-model-options="{trackBy: '$value'}" id="country" ng-model="signupFormData.country" placeholder="Select a Country">
<md-option ng-value="opt.id" ng-repeat="opt in countries">{{opt.name}}</md-option >
</md-select>
</md-input-container>
<md-button ng-submit class="md-raised md-primary">Register</md-button>
</form>
现在有一个奇怪的行为。当我在 php 中 var_dump $_POST
值时,
array (size=1)
'_country' => string '? string:AU ?' (length=13)
字段名称中添加了下划线..!此外,该值仍然不是预期的“AU”。
最佳答案
使用 opt.id
而不仅仅是 opt
作为您的 ng-value
,因为它包含您要发布的值。
关于javascript - 在 Angular Material 中提交选择选项值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34376877/