I want to save the value contained in multiple checkboxes only if they are checked. They would be saved into a MySQL database, using php. Here is my HTML code.
<div class="panel" ng-controller="checkBoxController">
<input class="form-control" placeholder="Cherchez vos contacts" type="text" ng-model="searchText">
</br>
<div ng-repeat="employee in employees | filter:searchText ">
<label class="action-checkbox">
<input id="{{employee.name}}" type="checkbox" value="{{employee.name}}" ng-checked="selection.indexOf(employee.name) > -1" ng-click="toggleSelection(employee.name)">
</label>
<label for="{{employee.name}}"></label>
{{employee.name}}
</label>
</div>
</br>
<span class="selected-item">Destinataires choisis:<span>
<div ng-repeat="name in selection" class="selected-item">
{{name}}
</div>
</div>
Here is my JS code.
var myApp = angular.module('myApp', []);
myApp.controller('checkBoxController', function($scope, $http) {
$http.get("information.php")
.success(function (response) {
$scope.employees = response.records;
});
$scope.selection = [];
// toggle selection for a given employee by name
$scope.toggleSelection = function toggleSelection(employeeName) {
var idx = $scope.selection.indexOf(employeeName);
if (idx > -1) {
$scope.selection.splice(idx, 1);
} else {
$scope.selection.push(employeeName);
}
};
});
What is the next step? Maybe save in a JSON file and send by HTTP post? I am lost.
$http.get
to get your employees data from php. You can use$http.post
to send data to php. So basicly$http.post("myfile.php", {selection: $scope.selection})
for example. – Guinn Jul 9 '15 at 12:37