javascript - Angularjs don't post hidden value -
i make $http.post
call, hidden fields not posted form.
code:
<sf:form ng-submit="post(form)" id="respond" > <input type="hidden"name="form.replyto" ng-model="replyto" ng-value="1"> <input type="hidden" name="form.id" ng-model="id" ng-value="33" > <input class="diskafield" type="text" ng-model="form.name" > <input class="diskafield" type="text" ng-model="form.email" > <textarea class="diskafield" name="comments" ng-model="form.body" required=""></textarea> <input class="diskabtn" type="button" ng-click="post(form)" value="post comment"> </div> </sf:form>
and controller :
app.controller('addcommentcontroller', function ($scope, $http) { $scope.name=""; $scope.email=""; $scope.body=""; $scope.id = ""; $scope.replyto = ''; $scope.post= function(form) { $http.post('http://localhost:8080/add', form).success(function(response){ }).error(function(response){ console.log(response); }) } });
your posting form
object so, if need attach hidden properties form
object,
<input type="hidden"name="form.replyto" ng-model="form.replyto" ng-value="1"> <input type="hidden" name="form.id" ng-model="form.id" ng-value="33" >
you need change model form.replyto
, form.id
above.
and seems have miss use ng-model
, name
,
for ex:
you mention $scope.name
and use in form element name.
that's not way use there no relation between scope variables , input names here.
that should related ng-model
.
so clean example should like.
$scope.form = { name : "", email : "", body : "", id : 33, replyto : 1 }; $scope.post= function(form) { $http.post('http://localhost:8080/add', form).success(function(response){ }).error(function(response){ console.log(response); }) } <sf:form ng-submit="post(form)" id="respond" > <input type="hidden"name="form.replyto" ng-model="form.replyto"> <input type="hidden" name="form.id" ng-model="form.id" > <input class="diskafield" type="text" ng-model="form.name" > <input class="diskafield" type="text" ng-model="form.email" > <textarea class="diskafield" name="comments" ng-model="form.body" required=""></textarea> <input class="diskabtn" type="button" ng-click="post(form)" value="post comment"> </div> </sf:form>
actually can remove 2 hidden fields since hidden field data exists in $scope.form
object.
here working demo
Comments
Post a Comment