zichzelf-invullend-formulier

Gesponsorde koppelingen

PHP script bestanden

  1. zichzelf-invullend-formulier

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<?php
header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
function
fetchURL( $url ) {
    $in = "";
    $url_parsed = parse_url($url);
    $host = $url_parsed["host"];
    if (!isset($url_parsed["port"])){
        $port = 80;
    }

    else
    {
        $port = $url_parsed["port"];
    }

    $path = $url_parsed["path"];
    //if url is http://example.com without final "/"
    //I was getting a 400 error

    if (empty($path) || empty($host))
    {

        die("Fout: geen path of host bekend");
    }

    if ($url_parsed["query"] != "")
    {

        $path .= "?".$url_parsed["query"];
    }

    $out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";
    $fp = fsockopen($host, $port, $errno, $errstr, 30);
    fwrite($fp, $out);
    $body = false;
    while (!feof($fp)) {
        $in .= fgets($fp, 128);
    }

    fclose($fp);
    return $in;
}


if(isset($_GET['search']))
{

    $url = "";
    foreach($_GET as $key => $value)
    {

        $url .= "&".$key."=".$value;
    }

    $data = split("ms-excel",fetchURL("http://www.nummerboek.com/index.php?".$url));
    echo $data[1];
}

else
{
    if($_SERVER['REQUEST_METHOD'] == "POST")
    {

        echo "<pre style=\"width: 470px;\">";
        print_r($_POST);
        echo "</pre>";
    }

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="test7/style.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>XMLHttpRequest test 7 - zichzelf invullend formulier</title>
<!--
    Dit script mag vrij gekopieert en bewerkt worden, zolang er niet wordt geclaimt
    dat het alleen door iemand anders is gemaakt dan mij.
    
    Ik zou het op prijs stellen als je jouw eventuele verbeteringen doorstuurt aan mij,
    zodat iedereen ervan kan proviteren.

    Ik hoop dat je er iets aan hebt,
    vrienderlijke groeten,

    Jelmer van der Linde
    ([email protected])
-->
<style>
label{
    display: block;
}
input[type="text"]{
    width: 100%;
}
#selectwindow
{
    border: 1px solid #666;
    background-color:#FFFFFF;
    -moz-border-radius: 4px;
    -moz-box-sizing: border-box;
    padding: 5px;
    display: block;
    width: 250px;
    height: 232px;
    position: absolute;
    z-index: 20;
    left: 150px;
    top: 80px;
}
</style>
<script type="text/javascript">
function obj(id)
{
    //omdat het sneller te typen is ^^,
    return document.getElementById(id).value;
}
function isset(object)
{
    if (null == object) {
        return false;
    }
    if ("undefined" == typeof(object) ) {
        return false;
    }
    return true;
}
function str_replace(needle, replacement, haystack)
{
    //ik kon geen vergelijkbare functie in javascript vinden, dus heb ik mijn eigen php-clone gemaakt.
    if(haystack.indexOf(needle))
    {
        var output = "";
        var temp = haystack.split(needle)
        for(i=0;i <= temp.length-1; i++)
        {
            if(i == 0)
            {
                output = temp[0];
            }
            else
            {
                output = output + replacement + temp[i];
            }
        }
        return output;
    }
    else
    {
        return haystack;
    }
}

function empty(obj)
{
    //omdat het sneller te typen is ^^,
    //php-clone
    if(document.getElementById(obj).value == "")
    {
        return true;
    }
    else
    {
        return false;
    }
}
function togglediv(id)
{
    if(document.getElementById(id).style.visibility == "hidden")
    {
        document.getElementById(id).style.visibility = "visible";
    }
    else
    {
        document.getElementById(id).style.visibility = "hidden";
    }
}
function fill(data)
{
    var line = data.split(",");
    var street = line[2].split(" ");
    var name = line[1].split(" ");
    var firstname = "";
    for(i = 1; name.length >= i+1; i++)
    {
        firstname = firstname +" "+ name[i];
    }
    document.getElementById('firstname').value = firstname;
    document.getElementById('lastname').value = name[0];
    document.getElementById('streetname').value = street[street.length-2];
    document.getElementById('housenumber').value = street[street.length-1];
    document.getElementById('postalcode').value = line[3];
    document.getElementById('townname').value = line[4];
//    document.getElementById('phonenumber').value = line[0].substring(4, line[0].length);// de eerste 3 karakters zijn rommel, en verneuken mijn form.
    document.getElementById('phonenumber').value = line[0];// de eerste 3 karakters zijn rommel, en verneuken mijn form.
    document.getElementById('status').innerHTML = "filled in data";
    
}
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}

function autofill()
{
    var url = "http://<?php echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];?>?sort=postalcode,housenr&search=1";
    if(('lastname'))
    {
        url = url + "&lastname=" + obj('lastname');
    }
    if(!empty('streetname'))
    {
        url = url + "&streetname=" + obj('streetname');
    }
    if(!empty('housenumber'))
    {
        url = url + "&housenumber" + obj('housenumber');
    }
    if(!empty('postalcode'))
    {
        url = url + "&postalcode=" + str_replace(" ", "", obj('postalcode'));
    }
    if(!empty('townname'))
    {
        url = url + "&townname_i=" + obj('townname');
    }
    if(!empty('phonenumber'))
    {
        url = url + "&phonenumber=" + str_replace("-", "", obj('phonenumber'));
    }
    url = url + "&export=csv";
    xmlhttp.open("GET", url,true);//method, target, async (set always true!)
    
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==0) {
            document.getElementById('status').innerHTML = "xmlhttprequest is uninitialized";
        }
        if (xmlhttp.readyState==1) {
            document.getElementById('status').innerHTML = "connecting...";
        }
        if (xmlhttp.readyState==2) {
            document.getElementById('status').innerHTML = "connection established";
        }
        if (xmlhttp.readyState==3) {
            document.getElementById('status').innerHTML = "retrieving data";
        }
        if (xmlhttp.readyState==4) {
            var data = xmlhttp.responseText;
            if(data != "Geen vermeldingen gevonden." && data != "" && data != null)
            {
                var rows = data.substr(4).split("\n");
                document.getElementById('status').innerHTML = rows.length+" resultaten gevonden.";
                //legen van selectbox
                document.forms['results'].resultslist.options.length = 0;
                if(rows.length <= 2)
                {
                    document.getElementById('status').innerHTML = "maar 1 reulstaat -> direct invullen";
                    fill(rows[0]);
                }
                else
                {
                    for(i = 0; i <= rows.length-1; i++)
                    {
                        if(isset(rows[i]))
                        {
                            if(rows[i] != "")
                            {
                                var line = rows[i].split(",");
                                document.forms['results'].resultslist.options[i] = new Option(line[1], rows[i]);
                            }
                        }
                    }
                    togglediv("selectwindow");
                }
            }
            else
            {
                document.getElementById('status').innerHTML = "no match found";
            }
        }
    }
    xmlhttp.send(null);
}
</script>
</head>

<body>

<fieldset style="width: 470px;">
    <legend>Persoonlijke Gegevens</legend>
    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
    <label for="firstname">Voornaam</label>
        <input type="text" name="firstname" id="firstname" /><br />
        
    <label for="lastname">Achternaam</label>
        <input type="text" name="lastname" id="lastname" /><br />
        
    <label for="streetname">Straat</label>
        <input type="text" name="streetname" id="streetname" /><br />
        
    <label for="housenumber">Huisnummer</label>
        <input type="text" name="housenumber" id="housenumber" /><br />
        
    <label for="postalcode">Postcode</label>
        <input type="text" name="postalcode" id="postalcode" /><br />

    <label for="townname">Stad</label>
        <input type="text" name="townname" id="townname" /><br />
    
    <label for="phonenumber">Telefoonummer</label>
        <input type="text" name="phonenumber" id="phonenumber" /><br />
    <br/>
    <fieldset class="error" style="width: 450px;">
        <p><input type="button" onclick="autofill()" value="Autofill()" /> Druk op "autofill()" om gegevens op te laten zoeken.</p>
    </fieldset>
    <br/>
    <input type="reset" />
    <input type="submit" />
    </form>
</fieldset>
<div id="selectwindow" style="visibility: hidden;">
    <form name="results">
        <select name="resultslist" size="12" style="width: 100%;" onchange="fill(this.options[this.selectedIndex].value);"></select>
        <input type="button" style="width: 100%; margin-top: 5px; float: none;" name="doeso" onclick="togglediv('selectwindow');" value="OK" />
    </form>
</div>
<span id="status"></span>
<br/>
<fieldset style="width: 470px; ">
    <!--<legend>&copy; Copyrights</legend>-->
    <p style="text-align:center;color: #666666;">Script door Jelmer van der Linde - GPL License<br/><!--mijn naam mag weg uit dit gedeelte, maar de vermelding bovenaan de pagina moet behouden blijven. -->
    Adresgegevens &copy; door <a href="http://www.telefoongids.e2u.cc">telefoongids.e2u.cc</a></p>
</fieldset>
</body>
</html>
<?php } ?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.