angularjs - angular select option not being passed to POST php -
this form, unfilled form, filed first form element shown on image dropdown list (select element options)
this form in question :
this select element :
<div class="form-group" ng-controller="clubsctrl"> <select class="form-control" style="margin-top:10px;" ng-options="club.id club.short_name club in clubs" ng-model="selected_club_id"> </select> <label>odaberite klub kojem igrač pripada</label> <p>test : id za odabrani klub :{{selected_club_id}}</p> </div> there other elements in form,for example:
<div class="row"> <div class="col-sm-6"> <div class="form-group"> <input type="text" class="form-control" id="firstname" ng-model="firstname"> <label for="firstname">ime</label> </div> </div> <div class="col-sm-6"> <div class="form-group"> <input type="text" class="form-control" id="lastname" ng-model="lastname"> <label for="lastname">prezime</label> </div> </div> </div> as can see, fill options in select element using the
clubsctrl. showing club names, once name clicked, id being selected. label below select shows id extracted (see second picture)
this call : class="btn btn-lg btn-primary btn-raised ink-reaction pull-right"> save
so can see calling function addplayer() playersctrl function :
$scope.addplayer = function() { $http.post('add_player.php', { 'selected_club_id' : $scope.selected_club_id, 'firstname' : $scope.firstname, 'lastname' : $scope.lastname, 'shirt_number' : $scope.shirt_number, 'position' : $scope.position, 'age' : $scope.age, 'national_team' : $scope.national_team, 'height' : $scope.height, 'weight' : $scope.weight, 'price' : $scope.price, 'ownership' : $scope.ownership, 'datum_rodjenja' : $scope.datum_rodjenja } ).success(function(data, status, headers, config) { infotime('<b>success</b>'); }); }; this add_player.php
<?php // including database connections require_once '../assets/database/config.php'; $data = json_decode(file_get_contents("php://input")); if (count($data) > 0) { // escape_string helper function $id_team = escape_string($data->selected_club_id); $firstname = escape_string($data->firstname); $lastname = escape_string($data->lastname); $shirt_number = escape_string($data->shirt_number); $position = escape_string($data->position); $age = escape_string($data->age); $national_team = escape_string($data->national_team); $height = escape_string($data->height); $weight = escape_string($data->weight); $price = escape_string($data->price); $ownership = escape_string($data->ownership); $datum_rodjenja = escape_string($data->datum_rodjenja); // query justa helper function $query = query("insert players(firstname, lastname, id_team, shirt_number, position, age, national_team, height, weight, price, ownership, date_of_birth, id_status) values('{$firstname}','{$lastname}','{$id_team}','{$shirt_number}','{$position}','{$age}','{$national_team}','{$height}','{$weight}','{$price}','{$ownership}','{$datum_rodjenja}', '1')"); $insert_result = confirm($query); // confirm = helper function # json-encode response echo $json_response = json_encode($insert_result); } ?>
the result:everythng gets inserted right,except $id_team, value thati got element
i have tried lot of things,nothing seems work. ifanybody has got hint or suggestion, pleasehelp.
thanx comments , suggestions. sorry formy bad english edis
clubsctrl creates new scope , selected value added different scope reading when try post value.
(sorry short answer, i'm on phone)
what you'll need use playersctrl 'as vm' construction , change ng-model select 'vm.selected_id'
let me know if need more help, i'll grab laptop , try elaborate.
edit
change route configuration include controlleras:'vm' controller in question. add property named 'vm' scope of controller
next change ng-model select 'vm.selected_id'
finally in function post, use $scope.vm.selected_id value.
that should work. prettier avoiding $scope completely, i'm on phone , it's inconvenient type code examples :)
Comments
Post a Comment