PluginProbe
Property Hive / 1.4.46
Property Hive v1.4.46
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / ph-form-functions.php

ph-form-functions.php in Property Hive 1.4.46, at includes/ph-form-functions.php

1,277 lines 44.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Form Functions
4 *
5 * Functions related to drawing forms on the frontend.
6 *
7 * @author PropertyHive
8 * @category Core
9 * @package PropertyHive/Functions
10 * @version 1.0.0
11 */
12
13 /**
14 * Main function for drawing entire property search form. We give the ability for an ID to be passed so differently formatted forms can be used
15 * (ie. a homepage search form might be different from a search form on search results)
16 *
17 * @param string $id
18 * @return void
19 */
20 function ph_get_search_form( $id = 'default' ) {
21
22 $form_controls = ph_get_search_form_fields();
23
24 $form_controls = apply_filters( 'propertyhive_search_form_fields_' . $id, $form_controls );
25 $form_controls = apply_filters( 'propertyhive_search_form_fields', $form_controls );
26
27 // We 100% need department so make sure it exists. If it doesn't, set a hidden field
28 if ( !isset($form_controls['department']) )
29 {
30 $original_form_controls = ph_get_search_form_fields();
31 $original_department = $original_form_controls['department'];
32 $original_department['type'] = 'hidden';
33
34 $form_controls['department'] = $original_department;
35 }
36
37 // append hidden order and view fields so these are maintained should a new search be performed
38 foreach ( $_REQUEST as $key => $value )
39 {
40 if ( isset($form_controls[$key]) )
41 continue;
42
43 if ( $key == 'officeID' && isset($form_controls['office']) )
44 continue;
45
46
47 // we've received a field that isn't a standard form control so let's store it in a hidden field so it's not lost
48 if ( is_array($value) )
49 {
50 foreach ( $value as $i => $val )
51 {
52 $form_controls[$key . '-' . $i] = array('type' => 'hidden', 'name' => $key . '[]', 'value' => stripslashes( ph_clean( $val) ));
53 }
54 }
55 else
56 {
57 $form_controls[$key] = array('type' => 'hidden', 'value' => stripslashes( ph_clean( $value) ));
58 }
59 }
60
61 ph_get_template( 'global/search-form.php', array( 'form_controls' => $form_controls, 'id' => $id ) );
62
63 }
64
65 /**
66 * Get default fields to be shown on search forms
67 *
68 * @return array
69 */
70 function ph_get_search_form_fields()
71 {
72 $fields = array();
73
74 $departments = array();
75 $value = '';
76 if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' )
77 {
78 $departments['residential-sales'] = __( 'Sales', 'propertyhive' );
79 if ($value == '' && (get_option( 'propertyhive_primary_department' ) == 'residential-sales' || get_option( 'propertyhive_primary_department' ) === FALSE) )
80 {
81 $value = 'residential-sales';
82 }
83 }
84 if ( get_option( 'propertyhive_active_departments_lettings' ) == 'yes' )
85 {
86 $departments['residential-lettings'] = __( 'Lettings', 'propertyhive' );
87 if ($value == '' && get_option( 'propertyhive_primary_department' ) == 'residential-lettings')
88 {
89 $value = 'residential-lettings';
90 }
91 }
92 if ( get_option( 'propertyhive_active_departments_commercial' ) == 'yes' )
93 {
94 $departments['commercial'] = __( 'Commercial', 'propertyhive' );
95 if ($value == '' && get_option( 'propertyhive_primary_department' ) == 'commercial')
96 {
97 $value = 'commercial';
98 }
99 }
100
101 $fields['department'] = array(
102 'type' => 'radio',
103 'options' => $departments,
104 'value' => $value
105 );
106
107 if ( array_key_exists('residential-sales', $departments) || array_key_exists('residential-lettings', $departments) )
108 {
109 if ( array_key_exists('residential-sales', $departments) )
110 {
111 $prices = array(
112 '' => __( 'No preference', 'propertyhive' ),
113 '100000' => '&pound;100,000',
114 '150000' => '&pound;150,000',
115 '200000' => '&pound;200,000',
116 '250000' => '&pound;250,000',
117 '300000' => '&pound;300,000',
118 '500000' => '&pound;500,000',
119 '750000' => '&pound;750,000',
120 '1000000' => '&pound;1,000,000'
121 );
122
123 $fields['minimum_price'] = array(
124 'type' => 'select',
125 'show_label' => true,
126 'label' => __( 'Min Price', 'propertyhive' ),
127 'before' => '<div class="control control-minimum_price sales-only">',
128 'options' => $prices
129 );
130
131 $fields['maximum_price'] = array(
132 'type' => 'select',
133 'show_label' => true,
134 'label' => __( 'Max Price', 'propertyhive' ),
135 'before' => '<div class="control control-maximum_price sales-only">',
136 'options' => $prices
137 );
138 }
139
140 if ( array_key_exists('residential-lettings', $departments) )
141 {
142 $prices = array(
143 '' => __( 'No preference', 'propertyhive' ),
144 '500' => '&pound;500 PCM',
145 '600' => '&pound;600 PCM',
146 '750' => '&pound;750 PCM',
147 '1000' => '&pound;1000 PCM',
148 '1250' => '&pound;1250 PCM',
149 '1500' => '&pound;1500 PCM',
150 '2000' => '&pound;2000 PCM'
151 );
152
153 $fields['minimum_rent'] = array(
154 'type' => 'select',
155 'show_label' => true,
156 'label' => __( 'Min Rent', 'propertyhive' ),
157 'before' => '<div class="control control-minimum_rent lettings-only">',
158 'options' => $prices
159 );
160
161 $fields['maximum_rent'] = array(
162 'type' => 'select',
163 'show_label' => true,
164 'label' => __( 'Max Rent', 'propertyhive' ),
165 'before' => '<div class="control control-maximum_rent lettings-only">',
166 'options' => $prices
167 );
168 }
169
170 $fields['minimum_bedrooms'] = array(
171 'type' => 'select',
172 'show_label' => true,
173 'label' => __( 'Min Beds', 'propertyhive' ),
174 'before' => '<div class="control control-minimum_bedrooms residential-only">',
175 'options' => array( '' => __( 'No preference', 'propertyhive' ), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5)
176 );
177
178 $fields['property_type'] = array(
179 'type' => 'property_type',
180 'show_label' => true,
181 'before' => '<div class="control control-property_type residential-only">',
182 'label' => __( 'Type', 'propertyhive' ),
183 );
184 }
185
186 if ( array_key_exists('commercial', $departments) )
187 {
188 $sizes = array(
189 '' => __( 'No preference', 'propertyhive' ),
190 '250' => '250 sq ft',
191 '500' => '500 sq ft',
192 '1000' => '1,000 sq ft',
193 '2500' => '2,500 sq ft',
194 '5000' => '5,000 sq ft',
195 '10000' => '10,000 sq ft',
196 '25000' => '25,000 sq ft',
197 '50000' => '50,000 sq ft'
198 );
199
200 $fields['minimum_floor_area'] = array(
201 'type' => 'select',
202 'show_label' => true,
203 'label' => __( 'Min Floor Area', 'propertyhive' ),
204 'before' => '<div class="control control-minimum_floor_area commercial-only">',
205 'options' => $sizes
206 );
207
208 $fields['maximum_floor_area'] = array(
209 'type' => 'select',
210 'show_label' => true,
211 'label' => __( 'Max Floor Area', 'propertyhive' ),
212 'before' => '<div class="control control-maximum_floor_area commercial-only">',
213 'options' => $sizes
214 );
215
216 // Property Type
217 $options = array( '' => __( 'No preference', 'propertyhive' ) );
218 $args = array(
219 'hide_empty' => false,
220 'parent' => 0
221 );
222 $terms = get_terms( 'commercial_property_type', $args );
223
224 $selected_value = '';
225 if ( !empty( $terms ) && !is_wp_error( $terms ) )
226 {
227 foreach ($terms as $term)
228 {
229 $options[$term->term_id] = $term->name;
230
231 $args = array(
232 'hide_empty' => false,
233 'parent' => $term->term_id
234 );
235 $subterms = get_terms( 'commercial_property_type', $args );
236
237 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
238 {
239 foreach ($subterms as $term)
240 {
241 $options[$term->term_id] = '- ' . $term->name;
242 }
243 }
244 }
245 }
246
247 $fields['commercial_property_type'] = array(
248 'type' => 'select',
249 'show_label' => true,
250 'before' => '<div class="control control-commercial_property_type commercial-only">',
251 'label' => __( 'Type', 'propertyhive' ),
252 'options' => $options
253 );
254 }
255
256 return $fields;
257 }
258
259 /**
260 * Main function for drawing property enquiry form.
261 *
262 * @param string $id
263 * @return void
264 */
265 function propertyhive_enquiry_form( $property_id = '' )
266 {
267 $form_controls = ph_get_property_enquiry_form_fields( $property_id );
268
269 $form_controls = apply_filters( 'propertyhive_property_enquiry_form_fields', $form_controls );
270
271 ph_get_template( 'global/make-enquiry-form.php',array( 'form_controls' => $form_controls ) );
272 }
273
274 /**
275 * Get default fields to be shown on search forms
276 *
277 * @return array
278 */
279 function ph_get_property_enquiry_form_fields( $property_id = '' )
280 {
281 global $post;
282
283 $fields = array();
284
285 $fields['property_id'] = array(
286 'type' => 'hidden',
287 'value' => ( $property_id != '' ? $property_id : $post->ID )
288 );
289
290 $fields['name'] = array(
291 'type' => 'text',
292 'label' => __( 'Full Name', 'propertyhive' ),
293 'required' => true
294 );
295 if ( is_user_logged_in() )
296 {
297 $current_user = wp_get_current_user();
298
299 $fields['name']['value'] = $current_user->display_name;
300 }
301
302 $fields['email_address'] = array(
303 'type' => 'email',
304 'label' => __( 'Email Address', 'propertyhive' ),
305 'required' => true
306 );
307 if ( is_user_logged_in() )
308 {
309 $current_user = wp_get_current_user();
310
311 $fields['email_address']['value'] = $current_user->user_email;
312 }
313
314 $fields['telephone_number'] = array(
315 'type' => 'text',
316 'label' => __( 'Number', 'propertyhive' ),
317 'required' => true
318 );
319
320 $fields['message'] = array(
321 'type' => 'textarea',
322 'label' => __( 'Message', 'propertyhive' ),
323 'required' => true
324 );
325
326 if ( get_option( 'propertyhive_property_enquiry_form_disclaimer', '' ) != '' )
327 {
328 $disclaimer = get_option( 'propertyhive_property_enquiry_form_disclaimer', '' );
329
330 $fields['disclaimer'] = array(
331 'type' => 'checkbox',
332 'label' => $disclaimer,
333 'label_style' => 'width:100%;',
334 'required' => true
335 );
336 }
337
338 return $fields;
339 }
340
341 /**
342 * Get default fields to be shown on applicant registration forms
343 *
344 * @return array
345 */
346 function ph_get_user_details_form_fields()
347 {
348 global $post;
349
350 if ( is_user_logged_in() )
351 {
352 $current_user = wp_get_current_user();
353
354 if ( $current_user instanceof WP_User )
355 {
356 $contact = new PH_Contact( '', $current_user->ID );
357 }
358 }
359
360 $fields = array();
361
362 $fields['name'] = array(
363 'type' => 'text',
364 'label' => __( 'Full Name', 'propertyhive' ),
365 'required' => true
366 );
367 if ( is_user_logged_in() && $current_user instanceof WP_User )
368 {
369 $fields['name']['value'] = $current_user->display_name;
370 }
371
372 $fields['email_address'] = array(
373 'type' => 'email',
374 'label' => __( 'Email Address', 'propertyhive' ),
375 'required' => true
376 );
377 if ( is_user_logged_in() && $current_user instanceof WP_User )
378 {
379 $fields['email_address']['value'] = $current_user->user_email;
380 }
381
382 $fields['telephone_number'] = array(
383 'type' => 'text',
384 'label' => __( 'Telephone Number', 'propertyhive' ),
385 'required' => false
386 );
387 if ( is_user_logged_in() && $current_user instanceof WP_User )
388 {
389 $fields['telephone_number']['value'] = $contact->telephone_number;
390 }
391
392 if ( get_option( 'propertyhive_applicant_users', '' ) == 'yes' )
393 {
394 $fields['password'] = array(
395 'type' => 'password',
396 'label' => __( 'Password', 'propertyhive' ),
397 'required' => true
398 );
399
400 $fields['password2'] = array(
401 'type' => 'password',
402 'label' => __( 'Confirm Password', 'propertyhive' ),
403 'required' => true
404 );
405 }
406
407 return $fields;
408 }
409
410 /**
411 * Get default fields to be shown on applicant registration forms
412 *
413 * @return array
414 */
415 function ph_get_applicant_requirements_form_fields()
416 {
417 global $post;
418
419 if ( is_user_logged_in() )
420 {
421 $current_user = wp_get_current_user();
422 $applicant_profile = false;
423
424 if ( $current_user instanceof WP_User )
425 {
426 $contact = new PH_Contact( '', $current_user->ID );
427
428 if ( is_array($contact->contact_types) && in_array('applicant', $contact->contact_types) )
429 {
430 if (
431 $contact->applicant_profiles != '' &&
432 $contact->applicant_profiles > 0 &&
433 $contact->applicant_profile_0 != '' &&
434 is_array($contact->applicant_profile_0)
435 )
436 {
437 $applicant_profile = $contact->applicant_profile_0;
438 }
439 }
440 }
441 }
442
443 $fields = array();
444
445 $offices = array();
446 $value = '';
447
448 $args = array(
449 'post_type' => 'office',
450 'nopaging' => true,
451 'orderby' => 'title',
452 'order' => 'ASC'
453 );
454
455 $office_query = new WP_Query( $args );
456
457 if ( $office_query->have_posts() )
458 {
459 while ( $office_query->have_posts() )
460 {
461 $office_query->the_post();
462
463 $offices[get_the_ID()] = get_the_title();
464
465 if ( get_post_meta(get_the_ID(), 'primary', TRUE) == 1 )
466 {
467 $value = get_the_ID();
468 }
469 }
470 }
471 wp_reset_postdata();
472
473 $fields['office_id'] = array(
474 'type' => ( (count($offices) <= 1) ? 'hidden' : 'select' ),
475 'label' => __( 'Office', 'propertyhive' ),
476 'required' => false,
477 'show_label' => true,
478 'value' => $value,
479 'options' => $offices
480 );
481
482 $departments = array();
483 $value = '';
484 if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' )
485 {
486 $departments['residential-sales'] = __( 'Properties To Buy', 'propertyhive' );
487 if ($value == '' && (get_option( 'propertyhive_primary_department' ) == 'residential-sales' || get_option( 'propertyhive_primary_department' ) === FALSE) )
488 {
489 $value = 'residential-sales';
490 }
491 }
492 if ( get_option( 'propertyhive_active_departments_lettings' ) == 'yes' )
493 {
494 $departments['residential-lettings'] = __( 'Properties For Rent', 'propertyhive' );
495 if ($value == '' && get_option( 'propertyhive_primary_department' ) == 'residential-lettings')
496 {
497 $value = 'residential-lettings';
498 }
499 }
500 if ( get_option( 'propertyhive_active_departments_commercial' ) == 'yes' )
501 {
502 $departments['commercial'] = __( 'Commercial Properties', 'propertyhive' );
503 if ($value == '' && get_option( 'propertyhive_primary_department' ) == 'commercial')
504 {
505 $value = 'commercial';
506 }
507 }
508 $fields['department'] = array(
509 'type' => 'radio',
510 'label' => __( 'Looking For', 'propertyhive' ),
511 'required' => true,
512 'show_label' => true,
513 'value' => $value,
514 'options' => $departments
515 );
516 if ( is_user_logged_in() && isset($applicant_profile['department']) )
517 {
518 $fields['department']['value'] = $applicant_profile['department'];
519 }
520 if ( count($departments) == 1 )
521 {
522 $fields['department']['type'] = 'hidden';
523 }
524
525 if ( get_option( 'propertyhive_active_departments_sales' ) == 'yes' || get_option( 'propertyhive_active_departments_lettings' ) == 'yes' )
526 {
527 $fields['maximum_price'] = array(
528 'type' => 'number',
529 'label' => __( 'Maximum Price', 'propertyhive' ),
530 'style' => 'max-width:150px;',
531 'before' => '<div class="control control-minimum_price sales-only">',
532 'required' => false
533 );
534 if ( is_user_logged_in() && isset($applicant_profile['max_price']) )
535 {
536 $fields['maximum_price']['value'] = $applicant_profile['max_price'];
537 }
538
539 $fields['maximum_rent'] = array(
540 'type' => 'number',
541 'label' => __( 'Maximum Rent', 'propertyhive' ) . ' (PCM)',
542 'style' => 'max-width:150px;',
543 'before' => '<div class="control control-minimum_price lettings-only">',
544 'required' => false
545 );
546 if ( is_user_logged_in() && isset($applicant_profile['max_rent']) )
547 {
548 $fields['maximum_rent']['value'] = $applicant_profile['max_rent'];
549 }
550
551 $fields['minimum_bedrooms'] = array(
552 'type' => 'number',
553 'label' => __( 'Minimum Bedrooms', 'propertyhive' ),
554 'style' => 'max-width:80px;',
555 'before' => '<div class="control control-minimum_bedrooms residential-only">',
556 'required' => false
557 );
558 if ( is_user_logged_in() && isset($applicant_profile['min_beds']) )
559 {
560 $fields['minimum_bedrooms']['value'] = $applicant_profile['min_beds'];
561 }
562
563 $args = array(
564 'hide_empty' => false,
565 'parent' => 0
566 );
567 $terms = get_terms( 'property_type', $args );
568
569 $options = array();
570
571 $selected_value = '';
572 if ( !empty( $terms ) && !is_wp_error( $terms ) )
573 {
574 $options = array( '' => __( 'All Property Types', 'properthive' ) );
575
576 foreach ($terms as $term)
577 {
578 $options[$term->term_id] = $term->name;
579
580 $args = array(
581 'hide_empty' => false,
582 'parent' => $term->term_id
583 );
584 $subterms = get_terms( 'property_type', $args );
585
586 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
587 {
588 foreach ($subterms as $term)
589 {
590 $options[$term->term_id] = '- ' . $term->name;
591 }
592 }
593 }
594 }
595
596 if ( !empty($options) )
597 {
598 $fields['property_type'] = array(
599 'type' => 'select',
600 'label' => __( 'Property Type', 'propertyhive' ),
601 'before' => '<div class="control control-property_type residential-only">',
602 'required' => false,
603 'options' => $options,
604 );
605
606 if ( is_user_logged_in() && isset($applicant_profile['property_types']) && is_array($applicant_profile['property_types']) && !empty($applicant_profile['property_types']) )
607 {
608 $fields['property_type']['value'] = $applicant_profile['property_types'][0];
609 }
610 }
611 }
612
613 if ( get_option( 'propertyhive_active_departments_commercial' ) == 'yes' )
614 {
615 $fields['available_as_sale'] = array(
616 'type' => 'checkbox',
617 'label' => __( 'For Sale', 'propertyhive' ),
618 'before' => '<div class="control control-available_as_sale commercial-only">',
619 'required' => false,
620 );
621 if ( is_user_logged_in() && isset($applicant_profile['available_as']) && in_array('sale', $applicant_profile['available_as']) )
622 {
623 $fields['available_as_sale']['checked'] = true;
624 }
625
626 $fields['available_as_rent'] = array(
627 'type' => 'checkbox',
628 'label' => __( 'To Rent', 'propertyhive' ),
629 'before' => '<div class="control control-available_as_rent commercial-only">',
630 'required' => false,
631 );
632 if ( is_user_logged_in() && isset($applicant_profile['available_as']) && in_array('rent', $applicant_profile['available_as']) )
633 {
634 $fields['available_as_rent']['checked'] = true;
635 }
636
637 $fields['minimum_floor_area'] = array(
638 'type' => 'number',
639 'label' => __( 'Min Floor Area (Sq Ft)', 'propertyhive' ),
640 'style' => 'max-width:150px;',
641 'before' => '<div class="control control-minimum_floor_area commercial-only">',
642 'required' => false
643 );
644 if ( is_user_logged_in() && isset($applicant_profile['min_floor_area']) )
645 {
646 $fields['minimum_floor_area']['value'] = $applicant_profile['min_floor_area'];
647 }
648
649 $fields['maximum_floor_area'] = array(
650 'type' => 'number',
651 'label' => __( 'Max Floor Area (Sq Ft)', 'propertyhive' ),
652 'style' => 'max-width:150px;',
653 'before' => '<div class="control control-maximum_floor_area commercial-only">',
654 'required' => false
655 );
656 if ( is_user_logged_in() && isset($applicant_profile['max_floor_area']) )
657 {
658 $fields['maximum_floor_area']['value'] = $applicant_profile['max_floor_area'];
659 }
660
661 $args = array(
662 'hide_empty' => false,
663 'parent' => 0
664 );
665 $terms = get_terms( 'commercial_property_type', $args );
666
667 $options = array();
668
669 $selected_value = '';
670 if ( !empty( $terms ) && !is_wp_error( $terms ) )
671 {
672 $options = array( '' => __( 'All Property Types', 'properthive' ) );
673
674 foreach ($terms as $term)
675 {
676 $options[$term->term_id] = $term->name;
677
678 $args = array(
679 'hide_empty' => false,
680 'parent' => $term->term_id
681 );
682 $subterms = get_terms( 'commercial_property_type', $args );
683
684 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
685 {
686 foreach ($subterms as $term)
687 {
688 $options[$term->term_id] = '- ' . $term->name;
689 }
690 }
691 }
692 }
693
694 if ( !empty($options) )
695 {
696 $fields['commercial_property_type'] = array(
697 'type' => 'select',
698 'label' => __( 'Property Type', 'propertyhive' ),
699 'before' => '<div class="control control-commercial_property_type commercial-only">',
700 'required' => false,
701 'options' => $options,
702 );
703
704 if ( is_user_logged_in() && isset($applicant_profile['commercial_property_types']) && is_array($applicant_profile['commercial_property_types']) && !empty($applicant_profile['commercial_property_types']) )
705 {
706 $fields['commercial_property_type']['value'] = $applicant_profile['commercial_property_types'][0];
707 }
708 }
709 }
710
711 $args = array(
712 'hide_empty' => false,
713 'parent' => 0
714 );
715 $terms = get_terms( 'location', $args );
716
717 $options = array();
718
719 $selected_value = '';
720 if ( !empty( $terms ) && !is_wp_error( $terms ) )
721 {
722 $options = array( '' => __( 'All Locations', 'properthive' ) );
723
724 foreach ($terms as $term)
725 {
726 $options[$term->term_id] = $term->name;
727
728 $args = array(
729 'hide_empty' => false,
730 'parent' => $term->term_id
731 );
732 $subterms = get_terms( 'location', $args );
733
734 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
735 {
736 foreach ($subterms as $term)
737 {
738 $options[$term->term_id] = '- ' . $term->name;
739 }
740 }
741 }
742 }
743
744 if ( !empty($options) )
745 {
746 $fields['location'] = array(
747 'type' => 'select',
748 'label' => __( 'Location', 'propertyhive' ),
749 'required' => false,
750 'options' => $options,
751 );
752
753 if ( is_user_logged_in() && isset($applicant_profile['locations']) && is_array($applicant_profile['locations']) && !empty($applicant_profile['locations']) )
754 {
755 $fields['location']['value'] = $applicant_profile['locations'][0];
756 }
757 }
758
759 $fields['additional_requirements'] = array(
760 'type' => 'textarea',
761 'label' => __( 'Additional Requirements', 'propertyhive' ),
762 'required' => false
763 );
764 if ( is_user_logged_in() && isset($applicant_profile['notes']) )
765 {
766 $fields['additional_requirements']['value'] = $applicant_profile['notes'];
767 }
768
769 return $fields;
770 }
771
772 /**
773 * Output individual field
774 *
775 * @return void
776 */
777 function ph_form_field( $key, $field )
778 {
779 global $post;
780
781 $output = '';
782
783 switch ($field['type'])
784 {
785 case "text":
786 case "email":
787 case "date":
788 case "number":
789 case "password":
790 {
791 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
792 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
793 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
794 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
795 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
796 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : ( ( $field['type'] == 'date' ) ? 'dd/mm/yyyy' : '' );
797 $field['required'] = isset( $field['required'] ) ? $field['required'] : false;
798 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
799
800 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
801 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
802 {
803 $field['value'] = sanitize_text_field( wp_unslash( $_GET[$key] ) );
804 }
805 else
806 {
807 if ( isset($post->ID) )
808 {
809 $value = get_post_meta( $post->ID, '_' . $key, true );
810 if ( $value != '' )
811 {
812 $field['value'] = $value;
813 }
814 }
815 }
816
817 $output .= $field['before'];
818
819 if ($field['show_label'])
820 {
821 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
822 if ($field['required'])
823 {
824 $output .= '<span class="required"> *</span>';
825 }
826 $output .= '</label>';
827 }
828
829 $output .= '<input
830 type="' . esc_attr( $field['type'] ) . '"
831 name="' . esc_attr( $key ) . '"
832 id="' . esc_attr( $key ) . '"
833 value="' . esc_attr( $field['value'] ) . '"
834 placeholder="' . esc_attr( $field['placeholder'] ) . '"
835 class="' . esc_attr( $field['class'] ) . '"
836 style="' . esc_attr( $field['style'] ) . '"
837 ' . ( ($field['required']) ? 'required' : '' ) . '
838 >';
839
840 $output .= $field['after'];
841
842 break;
843 }
844 case "textarea":
845 {
846 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
847 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
848 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
849 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
850 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
851 $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
852 $field['required'] = isset( $field['required'] ) ? $field['required'] : false;
853
854 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
855 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
856 {
857 $field['value'] = sanitize_textarea_field( wp_unslash( $_GET[$key] ) );
858 }
859 else
860 {
861 if ( isset($post->ID) )
862 {
863 $value = get_post_meta( $post->ID, '_' . $key, true );
864 if ( $value != '' )
865 {
866 $field['value'] = $value;
867 }
868 }
869 }
870
871 $output .= $field['before'];
872
873 if ($field['show_label'])
874 {
875 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
876 if ($field['required'])
877 {
878 $output .= '<span class="required"> *</span>';
879 }
880 $output .= '</label>';
881 }
882
883 $output .= '<textarea
884 name="' . esc_attr( $key ) . '"
885 id="' . esc_attr( $key ) . '"
886 placeholder="' . esc_attr( $field['placeholder'] ) . '"
887 class="' . esc_attr( $field['class'] ) . '"
888 ' . ( ($field['required']) ? 'required' : '' ) . '
889 >' . esc_attr( $field['value'] ) . '</textarea>';
890
891 $output .= $field['after'];
892
893 break;
894 }
895 case "checkbox":
896 {
897 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
898 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
899 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
900 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
901 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
902 $field['label_style'] = isset( $field['label_style'] ) ? $field['label_style'] : '';
903 $field['value'] = isset( $field['value'] ) ? $field['value'] : 'yes';
904 $field['checked'] = isset( $field['checked'] ) ? $field['checked'] : false;
905 if ( isset( $_GET[$key] ) && sanitize_text_field(wp_unslash($_GET[$key])) == $field['value'] )
906 {
907 $field['checked'] = true;
908 }
909 else
910 {
911 if ( isset($post->ID) )
912 {
913 $value = get_post_meta( $post->ID, '_' . $key, true );
914 if ( $value == 'yes' )
915 {
916 $field['checked'] = true;
917 }
918 }
919 }
920
921 $output .= $field['before'];
922
923 $output .= '<label style="' . esc_attr( $field['label_style'] ) . '"><input
924 type="' . esc_attr( $field['type'] ) . '"
925 name="' . esc_attr( $key ) . '"
926 value="' . esc_attr( $field['value'] ) . '"
927 class="' . esc_attr( $field['class'] ) . '"
928 ' . checked( $field['checked'], true, false ) . '
929 >';
930 if ($field['show_label'])
931 {
932 $output .= ' <span>' . $field['label'] . '</span>';
933 }
934 $output .= '</label>';
935
936 $output .= $field['after'];
937
938 break;
939 }
940 case "radio":
941 {
942 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
943 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
944 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
945 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : false;
946 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
947
948 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
949 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
950 {
951 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
952 }
953
954 $output .= $field['before'];
955
956 if ($field['show_label'])
957 {
958 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
959 }
960
961 foreach ( $field['options'] as $option_key => $value )
962 {
963 $output .= '<label><input
964 type="' . esc_attr( $field['type'] ) . '"
965 name="' . esc_attr( $key ) . '"
966 value="' . esc_attr( $option_key ) . '"
967 class="' . esc_attr( $field['class'] ) . '"
968 ' . checked( esc_attr( $field['value'] ), esc_attr( $option_key ), false ) . '
969 > ' . esc_html( $value ) . '</label>';
970 }
971
972 $output .= $field['after'];
973
974 break;
975 }
976 case "select":
977 {
978 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
979 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
980 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
981 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
982 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
983 $field['required'] = isset( $field['required'] ) ? $field['required'] : false;
984 $field['options'] = ( isset( $field['options'] ) && is_array( $field['options'] ) ) ? $field['options'] : array();
985
986 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
987 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
988 {
989 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
990 }
991 else
992 {
993 if ( isset($post->ID) )
994 {
995 $value = get_post_meta( $post->ID, '_' . $key, true );
996 if ( $value != '' )
997 {
998 $field['value'] = $value;
999 }
1000 }
1001 }
1002
1003 $output .= $field['before'];
1004
1005 if ($field['show_label'])
1006 {
1007 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'];
1008 if ($field['required'])
1009 {
1010 $output .= '<span class="required"> *</span>';
1011 }
1012 $output .= '</label>';
1013 }
1014
1015 $output .= '<select
1016 name="' . esc_attr( $key ) . '"
1017 id="' . esc_attr( $key ) . '"
1018 class="' . esc_attr( $field['class'] ) . '"
1019 >';
1020
1021 foreach ( $field['options'] as $option_key => $value )
1022 {
1023 $output .= '<option
1024 value="' . esc_attr( $option_key ) . '"
1025 ' . selected( esc_attr( $field['value'] ), esc_attr( $option_key ), false ) . '
1026 >' . esc_html( $value ) . '</option>';
1027 }
1028
1029 $output .= '</select>';
1030
1031 $output .= $field['after'];
1032
1033 break;
1034 }
1035 case "office":
1036 {
1037 $key = 'officeID';
1038
1039 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
1040 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1041 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1042 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
1043 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
1044
1045 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1046 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1047 {
1048 $field['value'] = (int)$_GET[$key];
1049 }
1050
1051 $output .= $field['before'];
1052
1053 if ($field['show_label'])
1054 {
1055 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
1056 }
1057
1058 $output .= '<select
1059 name="' . esc_attr( $key ) . '"
1060 id="' . esc_attr( $key ) . '"
1061 class="' . esc_attr( $field['class'] ) . '"
1062 >';
1063
1064 $output .= '<option
1065 value=""
1066 ' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . '
1067 >' . esc_html( __( 'No preference', 'propertyhive' ) ) . '</option>';
1068
1069 $args = array(
1070 'post_type' => 'office',
1071 'nopaging' => true,
1072 'orderby' => 'title',
1073 'order' => 'ASC'
1074 );
1075 $office_query = new WP_Query($args);
1076
1077 if ($office_query->have_posts())
1078 {
1079 while ($office_query->have_posts())
1080 {
1081 $office_query->the_post();
1082
1083 $output .= '<option
1084 value="' . esc_attr( $post->ID ) . '"
1085 ' . selected( esc_attr( $field['value'] ), esc_attr( $post->ID ), false ) . '
1086 >' . esc_html( get_the_title() ) . '</option>';
1087
1088 }
1089 }
1090 wp_reset_postdata();
1091
1092 $output .= '</select>';
1093
1094 $output .= $field['after'];
1095
1096 break;
1097 }
1098 case "country":
1099 {
1100 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
1101 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1102 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1103 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
1104 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
1105
1106 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1107 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1108 {
1109 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
1110 }
1111
1112 $output .= $field['before'];
1113
1114 if ($field['show_label'])
1115 {
1116 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
1117 }
1118
1119 $output .= '<select
1120 name="' . esc_attr( $key ) . '"
1121 id="' . esc_attr( $key ) . '"
1122 class="' . esc_attr( $field['class'] ) . '"
1123 >';
1124
1125 $output .= '<option
1126 value=""
1127 ' . selected( esc_attr( $field['value'] ), esc_attr( '' ), false ) . '
1128 >' . esc_html( __( 'No preference', 'propertyhive' ) ) . '</option>';
1129
1130 $countries = get_option( 'propertyhive_countries', array() );
1131 if ( is_array($countries) && !empty($countries) )
1132 {
1133 $ph_countries = new PH_Countries;
1134
1135 foreach ( $countries as $country )
1136 {
1137 $ph_country = $ph_countries->get_country( $country );
1138
1139 if ( $ph_country !== FALSE )
1140 {
1141 $output .= '<option
1142 value="' . esc_attr( $country ) . '"
1143 ' . selected( esc_attr( $field['value'] ), esc_attr( $country ), false ) . '
1144 >' . esc_html( $ph_country['name'] ) . '</option>';
1145 }
1146 }
1147 }
1148
1149 $output .= '</select>';
1150
1151 $output .= $field['after'];
1152
1153 break;
1154 }
1155 case "hidden":
1156 {
1157 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1158 $field['name'] = isset( $field['name'] ) ? $field['name'] : $key;
1159 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1160 {
1161 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
1162 }
1163
1164 $output .= '<input type="hidden" name="' . esc_attr( $field['name'] ) . '" value="' . $field['value'] . '">';
1165 break;
1166 }
1167 case "html":
1168 {
1169 $field['html'] = isset( $field['html'] ) ? $field['html'] : '';
1170 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1171 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1172
1173 $output .= $field['before'];
1174 $output .= $field['html'];
1175 $output .= $field['after'];
1176
1177 break;
1178 }
1179 case "recaptcha":
1180 {
1181 $field['site_key'] = isset( $field['site_key'] ) ? $field['site_key'] : '';
1182
1183 $output .= '<script src="https://www.google.com/recaptcha/api.js"></script>
1184 <div class="g-recaptcha" data-sitekey="' . $field['site_key'] . '"></div>';
1185 break;
1186 }
1187 default:
1188 {
1189 if ( taxonomy_exists($field['type']) )
1190 {
1191 $field['class'] = isset( $field['class'] ) ? $field['class'] : '';
1192 $field['before'] = isset( $field['before'] ) ? $field['before'] : '<div class="control control-' . $key . '">';
1193 $field['after'] = isset( $field['after'] ) ? $field['after'] : '</div>';
1194 $field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
1195 $field['label'] = isset( $field['label'] ) ? $field['label'] : '';
1196 $field['blank_option'] = isset( $field['blank_option'] ) ? $field['blank_option'] : __( 'No preference', 'propertyhive' );
1197
1198 $field['value'] = isset( $field['value'] ) ? $field['value'] : '';
1199 if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
1200 {
1201 $field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
1202 }
1203
1204 $output .= $field['before'];
1205
1206 if ($field['show_label'])
1207 {
1208 $output .= '<label for="' . esc_attr( $key ) . '">' . $field['label'] . '</label>';
1209 }
1210
1211 $output .= '<select
1212 name="' . esc_attr( $key ) . '"
1213 id="' . esc_attr( $key ) . '"
1214 class="' . esc_attr( $field['class'] ) . '"
1215 >';
1216
1217 $options = array( '' => $field['blank_option'] );
1218 $args = array(
1219 'hide_empty' => false,
1220 'parent' => 0
1221 );
1222 $terms = get_terms( $field['type'], $args );
1223
1224 $selected_value = '';
1225 if ( !empty( $terms ) && !is_wp_error( $terms ) )
1226 {
1227 foreach ($terms as $term)
1228 {
1229 $options[$term->term_id] = $term->name;
1230
1231 $args = array(
1232 'hide_empty' => false,
1233 'parent' => $term->term_id
1234 );
1235 $subterms = get_terms( $field['type'], $args );
1236
1237 if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
1238 {
1239 foreach ($subterms as $term)
1240 {
1241 $options[$term->term_id] = '- ' . $term->name;
1242
1243 $args = array(
1244 'hide_empty' => false,
1245 'parent' => $term->term_id
1246 );
1247 $subsubterms = get_terms( $field['type'], $args );
1248
1249 if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) )
1250 {
1251 foreach ($subsubterms as $term)
1252 {
1253 $options[$term->term_id] = '- ' . $term->name;
1254 }
1255 }
1256 }
1257 }
1258 }
1259 }
1260
1261 foreach ( $options as $option_key => $value )
1262 {
1263 $output .= '<option
1264 value="' . esc_attr( $option_key ) . '"
1265 ' . selected( esc_attr( $field['value'] ), esc_attr( $option_key ), false ) . '
1266 >' . esc_html( $value ) . '</option>';
1267 }
1268
1269 $output .= '</select>';
1270
1271 $output .= $field['after'];
1272 }
1273 }
1274 }
1275
1276 echo $output;
1277 }