使用您提供的鏈接中的示例,可以通過使用以下代碼更新代碼來訪問表單數據。
//添加字段對象作爲參數傳遞給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