autoaanvullen-straatnaam-en-woonplaats-bij-postcod

Gesponsorde koppelingen

PHP script bestanden

  1. autoaanvullen-straatnaam-en-woonplaats-bij-postcod

« Lees de omschrijving en reacties

index.html:

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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<body>
<script type="text/javascript">
function makeRequest() {
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) {
        return false;
    }
    http_request.onreadystatechange = alertContents;
    http_request.open('POST', 'script.php?method=lookup&postcode=' + document.req.postcode.value, true);
    http_request.send(null);
}


function alertContents() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            var xmldoc = http_request.responseXML;
            if (xmldoc.getElementsByTagName('street')[0].firstChild) {
                document.req.street.value = xmldoc.getElementsByTagName('street')[0].firstChild.nodeValue;
                document.req.city.value = xmldoc.getElementsByTagName('city')[0].firstChild.nodeValue;
            }

        }
    }
}
</script>

<h1>
Voorbeeld
</h1>
Vul een postcode in. De straatnaam en woonplaats worden automatisch ingevuld.
<form name="req">
<table>
  <tr>
    <td>Postcode:</td>
    <td><input type="text" name="postcode" id="postcode" onchange="makeRequest('postcode.xml');"></td>
</td>
  </tr>
  <tr>
    <td>Straatnaam:</td>
    <td><input type="text" name="street" disabled="disabled"></td>
  </tr>
  <tr>
    <td class="main">Woonplaats:</td>

    <td class="main"><input type="text" name="city" disabled="disabled"></td>
  </tr>
</table>
</form>
</body>
</html>


script.php
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
<?php
define ('HOSTNAME', 'http://6pp.kvdb.net/');

// Get the REST call path from the AJAX application
// Is it a POST or a GET?

$path = ($_POST['method']) ? $_POST['method'] : $_GET['method'];
$url = HOSTNAME.$path;

// Open the Curl session
$session = curl_init($url);

// If it's a POST, put the POST data in the body
if ($_POST['method']) {
    $postvars = '';
    while ($element = current($_POST)) {
                if (key($_POST) != 'method')
                {

            $postvars .= key($_POST).'='.$element.'&';
        }

        next($_POST);
    }
}


// Also append GET parameters
while ($element = current($_GET)) {
    if (key($_GET) != 'method')
        {

        $postvars .= key($_GET).'='.$element.'&';
    }

    next($_GET);
}


curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);

// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// Make the call
$xml = curl_exec($session);

// The web service returns XML. Set the Content-Type appropriately
header("Content-Type: text/xml");

echo $xml;
curl_close($session);

?>


Daniel

 
 

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.