传递由角函数获得的php post变量

时间:2015-10-30 17:00:29

标签: php angularjs

这是我的代码:

<form role="form" action="foo.php" method="post">
                        <p ng-repeat="item in selectedItems | orderBy: 'ora'">
                            Campo numero: {{item.id}} Orario: {{item.ora}}:00 Prezzo: €{{prezzoOra()}}.00
                        </p>
                        <p>
                            <b>Ore totali:</b> {{selectedItems.length}}<br>
                            <b>Prezzo Totale:</b> €{{total(selectedItems)}}.00
                        </p>
                        <input type="hidden" value="{{total(selectedItems)}}" name="totale" id="totale" />
                        <button type="button" class="btn btn-default" data-dismiss="modal">Indietro</button>

                        <input type="submit" value="Procedi con il pagamento" ng-click="prenota(selectedItems)" class="btn btn-primary">
</form>

当我尝试在foo.php页面中获取$ _POST ['totale']时,我获得的结果始终为0.

prenota功能:

$scope.prenota = function(selectedItems) {

    for(var i = 0, len = $scope.selectedItems.length; i < len; i++) {

        var id = selectedItems[i].id;
        var ora = selectedItems[i].ora;

        $http.post(base_path + "prenotazione/campi/prenota", {'id': id, 'ora': ora, 'data': $scope.data}).success(function(data,status,headers,config){

            $scope.myPromise =  $http.post(base_path + "prenotazione/campi/data", {'data': $scope.data}).success(function(data,status,headers,config){
                                    $scope.disponibilita = data;
                                });
        });

    }


    $scope.selectedItems = [];

};

有什么问题?

1 个答案:

答案 0 :(得分:0)

我不确定它是否适用于那样的值设置。 然后使用ng值(AngularJS&gt; = v1.2)设置输入,而不是插入范围。

<input type="hidden" ng-value="total(selectedItems)" name="totale" id="totale" />

另外,您是使用浏览器提交的本机表单还是通过函数prenota中的ajax请求发布?它可以帮助了解这个功能的内容。

相关问题