postal-search-tool.php
1.63 KB
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
<?php
/**
* Quotes Block Template.
*
* @param array $block The block settings and attributes.
* @param string $content The block inner HTML (empty).
* @param bool $is_preview True during AJAX preview.
* @param (int|string) $post_id The post ID this block is saved to.
*/
// Create id attribute allowing for custom "anchor" value.
$id = 'postal-search-' . $block['id'];
if( !empty($block['anchor']) ) {
$id = $block['anchor'];
}
// Create class attribute allowing for custom "className" and "align" values.
$className = 'postal-search';
if( !empty($block['className']) ) {
$className .= ' ' . $block['className'];
}
if( !empty($block['align']) ) {
$className .= ' align' . $block['align'];
}
if( $is_preview ) {
$className .= ' is-admin';
}
$postal_lookup = [];
$row = 0;
if (($handle = fopen(wp_get_upload_dir()['basedir']."/terriroties.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$row++;
if($row == 1) {
continue;
}
$postal_lookup[] = ['GEOKEY'=>$data[0],'PREFERRED'=>$data[3]];
}
fclose($handle);
}
?>
<div id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($className); ?>">
<div class='postal-code-inputs'>
<label>
<span class='label'>Enter Full Postal Code:</span>
<input type='text' class='postal-code-search' />
</label>
<label>
<span class='label'>Preferred?</span>
<input type='text' class='preferred' />
</label>
</div>
<input type='hidden' class='postal-search-data' value='<?= json_encode($postal_lookup) ?>' />
</div>