-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
169 lines (137 loc) · 5.18 KB
/
index.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>AJAX Postcode Lookup</title>
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Latest compiled and minified JavaScript -->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<style>
.block{
display: block;
}
#postcode {
text-transform: uppercase;
}
::-webkit-input-placeholder {
text-transform: initial;
}
:-moz-placeholder {
text-transform: initial;
}
::-moz-placeholder {
text-transform: initial;
}
:-ms-input-placeholder {
text-transform: initial;
}
</style>
<div class="col-sm-8 col-sm-offset-2 well" style="margin-top:50px;">
<h1>AJAX Postcode Lookup</h1>
<p>Postcode to address lookup using Google API</p>
<form action="process.php" method="post" class="ajax">
<div id="lookup-start">
<div class="form-group row">
<div class="col-sm-4">
<label>House / Flat / Building number or name</label>
<input id="number" type="text" name="number" class="form-control" placeholder="Number or house name">
</div>
<div class="col-sm-4">
<label>Postcode</label>
<input id="postcode" type="text" name="postcode" class="form-control" placeholder="Postcode">
</div>
<div class="col-sm-4">
<label> </label>
<button type="submit" id="submit" name="submit" value="send" class="btn btn-default block">Find my address</button>
</div>
</div>
</div>
<div id="lookup-complete" style="display: none;">
<div class="form-group">
<label>House / Flat / Building number or name</label>
<input id="number2" type="text" name="number2" class="form-control" placeholder="Number or house name">
</div>
<div class="form-group">
<label>Street</label>
<input id="street" type="text" name="street" class="form-control" placeholder="Street">
</div>
<div class="form-group">
<label>Town</label>
<input id="town" type="text" name="town" class="form-control" placeholder="Street">
</div>
<div class="form-group">
<label>County</label>
<input id="county" type="text" name="county" class="form-control" placeholder="Street">
</div>
<div class="form-group">
<label>Postcode</label>
<input id="postcode2" type="text" name="postcode2" class="form-control" placeholder="Postcode">
</div>
</div>
</form>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script>
/* Mirror data
-------------------------------------------------------*/
$('#number').bind('keypress keyup blur', function() {
$('#number2').val($(this).val());
});
$('#postcode').bind('keypress keyup blur', function() {
$('#postcode2').val($(this).val());
});
/* Post data to process sms
-------------------------------------------------------*/
$('form.ajax').on('submit', function(){
$('#submit, #number, #postcode').prop('disabled', true).html("sending");
var that = $(this),
url = that.attr('action'),
type = that.attr('method'),
data = {};
that.find('[name]').each(function(index, value){
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
});
$.ajax({
url: url,
type: type,
data: data,
success: function(data) {
console.log('success');
$('#submit').prop('disabled', false).html("Submit");
var parsed = JSON.parse(data);
$('#street').val(parsed.street);
$('#town').val(parsed.town);
$('#county').val(parsed.county);
$('#lookup-complete').fadeIn('fast');
$('#lookup-start').fadeOut('fast');
},
error: function(data) {
console.log('error');
},
complete: function() {
console.log('complete');
}
});
return false;
});
</script>
</body>
</html>