This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
75 lines (75 loc) · 2.2 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
<?php
# make sure we have the id
if( !empty($_REQUEST['id']) ) {
# get the requested address
$id = $_REQUEST['id'];
switch( $id ){
case '1':
$first = 'Bob';
$last = 'Smith';
$street = '123 School Street';
$city = 'Anytown';
$state = 'NY';
$zip = '12345';
break;
case '2':
$first = 'Janet';
$last = 'Jones';
$street = '123 Orange Ave';
$city = 'Somewhere';
$state = 'IA';
$zip = '54321';
break;
default:
# do nothing
break;
}
if( empty( $_REQUEST['submit'] ) ){
header( 'Content-Type: application/xml' );
echo "<file>
<name>
<first>$first</first>
<last>$last</last>
</name>
<address>
<street>$street</street>
<city>$city</city>
<state>$state</state>
<zip>$zip</zip>
</address>
</file>";
} else {
$txt = "$first $last\n$street\n$city, $state $zip";
showPage( $id, $txt );
}
} else {
showPage();
}
function showPage( $id=false, $address='' ){
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Ajax Address Book (XML Version)</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Language" content="en-us" />
<script type="text/javascript" src="../XHConn.js"></script>
<script type="text/javascript" src="addressBook.js"></script>
</head>
<body>
<h1>Simple Ajax Address Book</h1>
<form action="<?= $_SERVER['SCRIPT_NAME'] ?>" method="POST">
<fieldset>
<legend>Please Choose a Person</legend>
<select id="person" name="person">
<option value="">Choose Someone</option>
<option value="1"<?php echo( $id == 1 )? ' selected="selected"' : '' ?>>Bob Smith</option>
<option value="2"<?php echo( $id == 1 )? ' selected="selected"' : '' ?>>Janet Jones</option>
</select>
<input type="submit" id="submit" name="submit" value="Get the Address" />
</fieldset>
</form>
<pre id="address"><?= $address ?></pre>
</body>
</html><?
}
?>