我创建了一个包含3个组件(Divs)的页面,每个组件都有一个html表单,页面末尾有一个提交按钮。
我想知道使用单一提交按钮提交表单的最佳设计是什么?
我正在使用AngularJS。
发布于 2016-03-19 16:07:23
这一切都取决于您要在页面上完成的任务的上下文。理想情况下,您应该有一个单一的表单和一个提交按钮。我看到有三个带有三个提交按钮的表单的唯一原因是,如果您不要求在同一会话中提交其他一两个表单。尽管在使用angularjs时,您可以将所有内容收集到json对象中,并使用$http发送
工厂
app.factory('dataHandler',['$http', function($http){
var handle = this;
handle.send = function(params, actionUrl){
return $http({
url: actionUrl,
method: 'POST',
params: formParams,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
});
return handle;
}]);控制器
app.controller('Stage', ['dataHandler', '$scope', function(dataHandler, $scope){
var stage = this;
stage.processForm = function(){
dataHandler.sendOrder(stage.formInput, 'https://url.com/script')
.then(function (response) {
if (response.status == 200) {
console.log('Yay it worked');
}
});
}
}]);html
<form id="Form" name="Form" novalidate="novalidate">
<input type="checkbox" ng-model="stage.formInput.thisOption" ng-true-value="1" ng-false-value="0">
<input type="text" name="address_street" ng-model="stage.formInput.details.address.street" required>
</form>
<form id="Form2" name="Form2" novalidate="novalidate">
<input type="checkbox" ng-model="stage.formInput.thatOption" ng-true-value="1" ng-false-value="0">
<input type="text" name="address_street" ng-model="stage.formInput.details.address.suburb" required>
</form>
<button ng-click="stage.processForm()" name="button">Submit</button>https://stackoverflow.com/questions/36103537
复制相似问题