1 <?php
2
3 4 5 6 7
8
9 namespace nk2580\wordsmith\Inputs\Fields;
10
11 use nk2580\wordsmith\Inputs\Input as Input;
12
13 14 15 16 17
18 class AddressField extends Input {
19
20
21 public function printField() {
22 $class = $this->getClassString();
23 $value = unserialize($this->value);
24 echo '<div class="address-input">';
25 echo '<label>Line 1 <input type="text" class="'.$class.'" name="' . $this->name . '[line1]" value="'.$value['line1'].'" /></label><br/>';
26 echo '<label>Line 2 <input type="text" class="'.$class.'" name="' . $this->name . '[line2]" value="'.$value['line2'].'" /></label><br/>';
27 echo '<label>City <input type="text" class="'.$class.'" name="' . $this->name . '[city]" value="'.$value['city'].'" /></label><br/>';
28 echo '<label>State <input type="text" class="'.$class.'" name="' . $this->name . '[state]" value="'.$value['state'].'" /></label><br/>';
29 echo '<label>Postal Code <input type="text" class="'.$class.'" name="' . $this->name . '[postcode]" value="'.$value['postcode'].'" /></label><br/>';
30 echo '</div>';
31 }
32
33
34 public function isFieldValid() {
35 if (is_array($this->value)) {
36 return true;
37 }
38 else if(is_string($this->value)){
39 $arr = unserialize($this->value);
40 if(is_array($arr)){
41 return true;
42 }
43 else{
44 return false;
45 }
46 }else {
47 return false;
48 }
49 }
50
51 public function sanitize() {
52 return serialize($this->value);
53 }
54
55
56
57 }
58