使用您提供的链接中的示例,可以通过使用以下代码更新代码来访问表单数据。
//添加字段对象作为参数传递给submitForm()
<form name="signup_form" ng-controller="FormController" ng-submit="submitForm(fields)" novalidate>
//在$ scope.submitForm()函数...
$scope.submitForm = function(data) {
alert(data[0].name); // Alerts name
alert(data[1].name); // Alerts password
alert(data[2].name); // Alerts email
};
如果注销通过submitForm()接收到的数据,你会得到如下:
[{"placeholder":"Username","isRequired":true,"$$hashKey":"004","name":"random name"},{"placeholder":"Password","isRequired":true,"$$hashKey":"005","name":"password"},{"placeholder":"Email (optional)","isRequired":false,"$$hashKey":"006","name":"[email protected]"}]
对于传递到您的服务器,这个软件包都归结为是或格式化根据您的偏好,并通过$ scope.submitForm函数内部的$http.post()
或$resource()
中的内置函数发送给您的服务器。
格式化的数据的一个例子是:
$scope.submitForm = function(data) {
var postData = {};
postData.name = data[0].name;
postData.password = data[1].name;
postData.email = data[2].name;
... send postData to server via AJAX ...
// Creates the object: {"name":"random name","password":"password","email":"[email protected]"}
//alert(JSON.stringify(postData));
};
所有你谈论这些领域都有自己的ID。我的意思是,你应该从$ _POST var索引中检索它们:$ _POST ['name1'],$ _POST ['name2'],$ _POST ['name3'](其中name,name2和name3是输入的值'名称属性)。 – Alex
'var_dump($ _ POST)'在php文件中,你将不知所措并且如何得到它! – mohsen