我在控制器中有一个问题,我在科尔多瓦应用程序的表格中填写了我的数据。但是,如果所有字段都为空,则仍将其插入数据库中。
这是我目前的代码。
控制器作用域(添加功能)
$scope.addInvoice = function(){
console.log($scope.fileToUpload);
var formdata = new FormData();
var filedata = $scope.dataURLtoFile("data:image/jpeg;base64," + $rootScope.scan, 'scan.png');
formdata.append("title", "Factuur " + $scope.factuurNr);
formdata.append("imageselect", filedata);
formdata.append("command", "Invoices:uploadImage");
$.ajax({
type: 'POST',
url: gateway,
data: formdata,
mimeType: "multipart/form-data",
cache: false,
processData: false,
contentType: false,
success: function (data) {
swal("Geweldig!", "de bon is succesvol toegevoegd", "success");
data = JSON.parse(data);
$scope.docGuid = data.data;
$scope.$apply();
// addInvoice \\
// $ticket = $_POST['invoiceno'] ?: $_POST['ticket'] ?: null;
// $totInclVat = $_POST['totamount'] ?: $_POST['totInclVat'] ?: null;
// $docGuid = $_POST['docGuid'] ?: $_POST['docguid'] ?: null;
// $vatLow = $_POST['vatLow'] ?: $_POST['vatlow'] ?: null;
// $vatHigh = $_POST['vatHigh'] ?: $_POST['vathigh'] ?: null;
// echo $api->addInvoiceOut($ticket, $_POST['company'], $_POST['person'], $totInclVat, $vatLow, $vatHigh, $_POST['concerns'], $docGuid);
//END//
if($scope.newContact){
var type = "Bedrijf";
var company = $scope.inputCompany;
var formdata = $("").serializeArray();
formdata.push({"name": "firstName", "value": company});
formdata.push({"name": "type", "value": type});
formdata.push({"name": "command", "value": "Contacts:add"});
$.post(gateway, formdata, function (data) {
console.log(data);
var companyGuid = data.data;
var formdata = $("#bonForm").serializeArray();
formdata.push({"name": "company", "value": companyGuid});
formdata.push({"name": "docGuid", "value": $scope.docGuid});
formdata.push({"name": "person", "value": ""});
formdata.push({"name": "vatLow", "value": ""});
formdata.push({"name": "vatHigh", "value": ""});
formdata.push({"name": "billingStatus", "value": "60"});
formdata.push({"name": "command", "value": "Invoices:addInvoiceOut"});
$.post(gateway, formdata, function (data) {
console.log(data);
//admin_lifecycle
formdata.pop();
formdata.push({
"name": "vatcat",
"value": 0
});
formdata.push({
"name": "exvat",
"value": 0
});
formdata.push({
"name": "vat",
"value": 0
});
formdata.push({
"name": "command",
"value": "Invoices:addLifecycleLine"
});
$.post(gateway, formdata, function (data) {
console.log(data);
}, "json");
}, "json");
}, "json");
}else{
var formdata = $("#bonForm").serializeArray();
formdata.push({"name": "company", "value": $scope.selectedCompany.guid});
formdata.push({"name": "docGuid", "value": $scope.docGuid});
formdata.push({"name": "person", "value": ""});
formdata.push({"name": "vatLow", "value": ""});
formdata.push({"name": "vatHigh", "value": ""});
formdata.push({"name": "billingStatus", "value": "60"});
formdata.push({"name": "command", "value": "Invoices:addInvoiceOut"});
$.post(gateway, formdata, function (data) {
console.log(data);
// swal("Geweldig!", "de bon is succesvol toegevoegd", "success");
//admin_lifecycle
formdata.pop();
formdata.push({
"name": "vatcat",
"value": 0
});
formdata.push({
"name": "exvat",
"value": 0
});
formdata.push({
"name": "vat",
"value": 0
});
formdata.push({
"name": "command",
"value": "Invoices:addLifecycleLine"
});
$.post(gateway, formdata, function (data) {
console.log(data);
}, "json");
}, "json");
}
}
});
}
});
这是输入(前)
<form id="bonForm">
<div class="row">
<div class="form-group col-12">
<div class="row">
<div class="col-6 doc-check">
<input type="radio" ng-click="document=false" id="factuur" name="docCheck" checked>
<label ng-style="document == false && {'background':'#a44dac'}" for="factuur">Factuur</label>
</div>
<div class="col-6 doc-check">
<input type="radio" ng-click="document=true" id="document" name="docCheck">
<label ng-style="document == true && {'background':'#a44dac'}" for="document">Document</label>
</div>
</div>
</div>
<div class="form-group col-12">
<div class="wrapper">
<input id="company" class="form-fleximaal" name="company" type="text" ng-focus="focused = true" ng-model="inputCompany" placeholder="Bedrijf selecteren/zoeken"/>
<ul class="input-dropdown" ng-show="focused" ng-mouseleave="focused = false">
<li class="dropdown-option" ng-repeat="companie in companies | filter:{name: inputCompany} " ng-click="addInputCompany(companie)">
<p><i class="fas fa-building"></i>{{companie.name}}</p>
</li>
</ul>
</div>
</div>
<div class="form-group col-6" ng-hide="document">
<input type="text" class="form-fleximaal" name="invoiceno" ng-model="factuurNr" placeholder="Factuur nr." required="true">
</div>
<div class="form-group col-6" ng-show="document">
<input type="text" class="form-fleximaal" name="docnr" ng-model="documentNr" placeholder="Document nr." required="true">
</div>
<div class="form-group col-6">
<input class="form-fleximaal" type="date" name="dateDeadline" ng-model="documentDatum" placeholder="Documentdatum" required="true">
</div>
<div class="form-group col-12">
<input type="text" class="form-fleximaal" name="concerns" ng-model="betreft" placeholder="Betreft" required="true">
</div>
<div class="form-group col-12" ng-hide="document">
<input type="number" step="any" class="form-fleximaal" name="totamount" ng-model="inclprijs" placeholder="Prijs inclusief." required="true">
</div>
<div class="form-group col-12">
<button class="btn btn-fleximaal-dark" ng-click="addInvoice(); false" ng-hide="document">Factuur toevoegen</button>
<button class="btn btn-fleximaal-dark" ng-click="addDocument(); false" ng-show="document">Document toevoegen</button>
</div>
</div>
</form>
我希望有人可以帮助我建立支票。如果数据显示错误0,则说明该字段已正确填充。
答案 0 :(得分:0)
您需要编辑JavaScript的行(在if
和else
中,在其中使用jQuery声明serializeArray()
变量。你有:
var formdata = $("").serializeArray();
相反,它应该类似于:
var formdata = $("input[value!=''],checkbox[value!=''],radio[value!=''],select[value!='']").serializeArray();