-
Notifications
You must be signed in to change notification settings - Fork 0
/
form-display.php
129 lines (120 loc) · 4.69 KB
/
form-display.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<script>
var path = "<?php
$str = home_url();
$str.= '/wp-content/plugins/just-another-form';
echo $str;
?>";
getPath = path + "/getData.php";
postPath = path + "/insertdb.php";
</script>
<?php
$allCDN = <<<'ACDN'
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
ACDN;
$ngForm = <<<'NGF'
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"> </script>
<div ng-app="form" ng-controller="formCtrl">
<div class="col-md-8">
<form >
<div class="form-group col-md-6">
<label for="fname">First Name</label>
<input class="form-control" type="text" ng-model="fname" name="fname">
</div>
<div class="form-group col-md-6">
<label for="lname">Last Name</label>
<input class="form-control" type="text" ng-model="lname" name="lname">
</div>
<div class="form-group col-md-12">
<label for="email">E-mail</label>
<input class="form-control" type="email" ng-model="email" name="email">
</div>
<br>
<br>
<div class="form-group col-md-3" >
<input class="btn btn-success form-control" type="submit" value="Submit" ng-click="insertData()">
</div>
</form>
</div>
<br>
<div class="col-md-8">
<table style="text-align: center;" class="table-bordered col-md-12">
<thead><tr>
<th style="text-align: center; padding: 5px;">First Name</th>
<th style="text-align: center; padding: 5px;">Last Name</th>
<th style="text-align: center; padding: 5px;">E-mail</th>
</tr></thead>
<tr ng-repeat="x in names">
<td>{{ x.fname }}</td>
<td>{{ x.lname }}</td>
<td>{{ x.email }}</td>
</tr>
<tr>
<td>{{ fname }}</td>
<td>{{ lname }}</td>
<td>{{ email }}</td>
</tr>
</table>
</div>
</div>
NGF;
$ngScript = <<<'NGS'
<script>
var app = angular.module('form',[]);
app.controller('formCtrl', function($scope, $http) {
$scope.insertData=function(){
$http.get(getPath).then(function(response){
$scope.names = response.data.records;});
$http.post(postPath, {
'fname':$scope.fname,
'lname':$scope.lname,
'email':$scope.email
}).then(function(response){
console.log("Data Entered into database");
},function(error){
alert($scope.fname+$scope.lname+$scope.email+" Some error occured while inserting data to database");
console.error(error);
console.log("Data Entered into database");
});
},
$http.get(getPath)
.then(function (response) {$scope.names = response.data.records;});
});
</script>
NGS;
// $ngScript = <<< 'NGS'
// <script>
// var app = angular.module('form', []);
// app.controller('formCtrl', function ($scope, $http) {
// $scope.login = function () {
// $http({
// method: "post",
// url: path + "insertdb.php",
// data: {
// fname: $scope.fname,
// lname: $scope.lname,
// email: $scope.email
// },
// headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
// }).request.success(function (data) {
// if(data == "1"){
// $scope.responseMessage = "Successfully Logged In";
// alert("yes");
// }
// else{
// $scope.responseMessage = "Username or Password is incorrect";
// alert("no");
// }
// });
// $http.get(path + "/getData.php").success(function(data){
// $scope.data = data;
// }).error(function() {
// $scope.data = "error in fetching data";
// });
// }
// });
// </script>
// NGS;
echo "<br>".$ngForm."<br>".$ngScript;
?>