2

I recently started to study angular js. I am a bit lost with the http post, no matter what do i do i always get back null from the input

angular controller

function regCtrl ($scope, $http) { $scope.regSubmit = function() { $http.post(siteUrl + 'regisztracio', [{'felhasznalonev': $scope.felhasznalonev}]).success(function( data ){ alert(data.msg); }); } } 

laravel conroller

public function post_index() { $input = Input::json(); $input_array = (array)$input; $rules = array( 'felhasznalonev' => 'required' ); $val = Validator::make($input_array, $rules); if(! $val->fails() ) { $data = array('msg' => 'all good'); } else { $data = array('msg' => $val->errors->all()); } return Response::json($data); } 

form

<?php Section::start('content') ?> <div class="content" ng-controller="regCtrl"> <form class="span5 no-float centered" ng-submit="regSubmit()"> <label for="felhasznalonev">Felhasználó név</label> <input type="text" id="felhasznalonev" name="felhasznalonev" ng-model="felhasznalonev" class="span5"> <label for="email">Email</label> <input type="text" name="email" id="email" class="span5"> <label class="radio inline"> <input type="radio" name="nem">Férfi </label> <label class="radio inline"> <input type="radio" name="nem">Nő </label> <label class="checkbox"> <input type="checkbox" name="feltetel"><a href="" title="">Elfogadom a felhasználói feltételeket</a> </label> <button type="submit" class="btn btn-small btn-block">Regisztráció</button> </form> </div> <?php Section::stop() ?> 

could please someone give me a hint what i am doing wrong? i have been mesing with it 3 hours now

thank you

2 Answers 2

1

My bad, digged in to the documentation more deelply

submit function looks like this

$scope.regSubmit = function() { $http({ method: "POST", url: siteUrl + 'regisztracio', data: {felhasznalonev: $scope.felhasznalonev}, }).success(function(data){ alert(data.msg) }); } 

works like a charm

Sign up to request clarification or add additional context in comments.

Comments

1

I think you were close. Your $http just needed some changing.

function regCtrl ($scope, $http) { $scope.regSubmit = function() { $http.post(siteUrl + 'regisztracio', { felhasznalonev: $scope.felhasznalonev }).then(function(data){ alert(data.msg); }); } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.