',
'required' => false
);
if ( is_user_logged_in() && isset($applicant_profile['max_floor_area']) )
{
$fields['maximum_floor_area']['value'] = $applicant_profile['max_floor_area'];
}
$args = array(
'hide_empty' => false,
'parent' => 0
);
$terms = get_terms( 'commercial_property_type', $args );
$options = array();
$selected_value = '';
if ( !empty( $terms ) && !is_wp_error( $terms ) )
{
$options = array( '' => __( 'All Property Types', 'propertyhive' ) );
foreach ($terms as $term)
{
$options[$term->term_id] = $term->name;
$args = array(
'hide_empty' => false,
'parent' => $term->term_id
);
$subterms = get_terms( 'commercial_property_type', $args );
if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
{
foreach ($subterms as $term)
{
$options[$term->term_id] = '- ' . $term->name;
}
}
}
}
if ( !empty($options) )
{
$fields['commercial_property_type'] = array(
'type' => 'select',
'label' => __( 'Property Type', 'propertyhive' ),
'before' => '
',
'required' => false,
'multiselect' => true,
'options' => $options,
);
if ( is_user_logged_in() && isset($applicant_profile['commercial_property_types']) && is_array($applicant_profile['commercial_property_types']) && !empty($applicant_profile['commercial_property_types']) )
{
$fields['commercial_property_type']['value'] = $applicant_profile['commercial_property_types'];
}
}
}
if ( get_option('propertyhive_applicant_locations_type') != 'text' )
{
$args = array(
'hide_empty' => false,
'parent' => 0
);
$terms = get_terms( 'location', $args );
if ( !empty( $terms ) && !is_wp_error( $terms ) )
{
$fields['location'] = array(
'type' => 'location',
'label' => __( 'Location', 'propertyhive' ),
'blank_option' => __( 'All Locations', 'propertyhive' ),
'required' => false,
'multiselect' => true,
);
if ( is_user_logged_in() && isset($applicant_profile['locations']) && is_array($applicant_profile['locations']) && !empty($applicant_profile['locations']) )
{
$fields['location']['value'] = $applicant_profile['locations'];
}
}
}
else
{
$fields['location_text'] = array(
'type' => 'text',
'label' => __( 'Location', 'propertyhive' ),
'required' => false
);
if ( is_user_logged_in() && isset($applicant_profile['location_text']) && $applicant_profile['location_text'] != '' )
{
$fields['location_text']['value'] = $applicant_profile['location_text'];
}
}
$fields['additional_requirements'] = array(
'type' => 'textarea',
'label' => __( 'Additional Requirements', 'propertyhive' ),
'required' => false
);
if ( is_user_logged_in() && isset($applicant_profile['notes']) )
{
$fields['additional_requirements']['value'] = $applicant_profile['notes'];
}
return $fields;
}
/**
* Output individual field
*
* @return void
*/
function ph_form_field( $key, $field )
{
global $post;
$output = '';
switch ($field['type'])
{
case "text":
case "email":
case "date":
case "number":
case "password":
{
$field['id'] = isset( $field['id'] ) ? $field['id'] : $key;
$field['class'] = isset( $field['class'] ) ? $field['class'] : '';
$field['before'] = isset( $field['before'] ) ? $field['before'] : '
';
$field['after'] = isset( $field['after'] ) ? $field['after'] : '
';
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
$field['label'] = isset( $field['label'] ) ? $field['label'] : '';
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : ( ( $field['type'] == 'date' ) ? 'dd/mm/yyyy' : '' );
$field['required'] = isset( $field['required'] ) ? $field['required'] : false;
$field['style'] = isset( $field['style'] ) ? $field['style'] : '';
$field['value'] = isset( $field['value'] ) ? $field['value'] : '';
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
{
$field['value'] = sanitize_text_field( wp_unslash( $_GET[$key] ) );
}
else
{
if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) )
{
$value = get_post_meta( $post->ID, '_' . $key, true );
if ( $value != '' )
{
$field['value'] = $value;
}
}
}
$output .= $field['before'];
if ($field['show_label'])
{
$output .= '
';
}
$output .= '
';
$output .= $field['after'];
break;
}
case "textarea":
{
$field['class'] = isset( $field['class'] ) ? $field['class'] : '';
$field['before'] = isset( $field['before'] ) ? $field['before'] : '
';
$field['after'] = isset( $field['after'] ) ? $field['after'] : '
';
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
$field['label'] = isset( $field['label'] ) ? $field['label'] : '';
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
$field['required'] = isset( $field['required'] ) ? $field['required'] : false;
$field['value'] = isset( $field['value'] ) ? $field['value'] : '';
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
{
$field['value'] = sanitize_textarea_field( wp_unslash( $_GET[$key] ) );
}
else
{
if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) )
{
$value = get_post_meta( $post->ID, '_' . $key, true );
if ( $value != '' )
{
$field['value'] = $value;
}
}
}
$output .= $field['before'];
if ($field['show_label'])
{
$output .= '
';
}
$output .= '
';
$output .= $field['after'];
break;
}
case "checkbox":
{
$field['class'] = isset( $field['class'] ) ? $field['class'] : '';
$field['before'] = isset( $field['before'] ) ? $field['before'] : '
';
$field['after'] = isset( $field['after'] ) ? $field['after'] : '
';
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
$field['label'] = isset( $field['label'] ) ? $field['label'] : '';
$field['label_style'] = isset( $field['label_style'] ) ? $field['label_style'] : '';
$field['value'] = isset( $field['value'] ) ? $field['value'] : 'yes';
$field['checked'] = isset( $field['checked'] ) ? $field['checked'] : false;
if ( isset( $_GET[$key] ) && sanitize_text_field(wp_unslash($_GET[$key])) == $field['value'] )
{
$field['checked'] = true;
}
else
{
if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) )
{
$value = get_post_meta( $post->ID, '_' . $key, true );
if ( $value == 'yes' )
{
$field['checked'] = true;
}
}
}
$output .= $field['before'];
$output .= '
';
$output .= $field['after'];
break;
}
case "radio":
{
$field['class'] = isset( $field['class'] ) ? $field['class'] : '';
$field['before'] = isset( $field['before'] ) ? $field['before'] : '
';
$field['after'] = isset( $field['after'] ) ? $field['after'] : '
';
$field['before_option'] = isset( $field['before_option'] ) ? $field['before_option'] : '
';
$field['before_input'] = isset( $field['before_input'] ) ? $field['before_input'] : '';
$field['after_input'] = isset( $field['after_input'] ) ? $field['after_input'] : '';
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : false;
$field['label'] = isset( $field['label'] ) ? $field['label'] : '';
$field['options'] = ( isset( $field['options'] ) && is_array( $field['options'] ) ) ? $field['options'] : array();
$field['value'] = isset( $field['value'] ) ? $field['value'] : '';
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
{
$field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
}
$output .= $field['before'];
if ($field['show_label'])
{
// get first option as 'for'
$option_key = '';
foreach ( $field['options'] as $option_key => $value )
{
break;
}
$output .= '
';
}
foreach ( $field['options'] as $option_key => $value )
{
$id = esc_attr( $key ) . '_' . esc_attr( $option_key );
$output .= str_replace("{id}", $id, $field['before_option']);
$output .= str_replace("{id}", $id, $field['before_input']);
$output .= '
';
$output .= str_replace("{id}", $id, $field['after_input']);
$output .= ' ' . esc_html( $value );
$output .= str_replace("{id}", $id, $field['after_option']);
}
$output .= $field['after'];
break;
}
case "select":
{
$field['class'] = isset( $field['class'] ) ? $field['class'] : '';
$field['before'] = isset( $field['before'] ) ? $field['before'] : '
';
$field['after'] = isset( $field['after'] ) ? $field['after'] : '
';
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
$field['label'] = isset( $field['label'] ) ? $field['label'] : '';
$field['required'] = isset( $field['required'] ) ? $field['required'] : false;
$field['options'] = ( isset( $field['options'] ) && is_array( $field['options'] ) ) ? $field['options'] : array();
$field['multiselect'] = isset( $field['multiselect'] ) ? $field['multiselect'] : false;
if ( $field['multiselect'] )
{
wp_enqueue_script( 'multiselect' );
}
$field['value'] = isset( $field['value'] ) ? $field['value'] : '';
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
{
$field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
}
else
{
if ( !is_post_type_archive('property') && !is_singular('property') && isset($post->ID) )
{
$value = get_post_meta( $post->ID, '_' . $key, true );
if ( $value != '' )
{
$field['value'] = $value;
}
}
}
$output .= $field['before'];
if ($field['show_label'])
{
$output .= '
';
}
$blank_option = '';
foreach ( $field['options'] as $option_key => $value )
{
if ( $field['multiselect'] && $option_key == '' )
{
$blank_option = $value;
continue;
}
}
$output .= '
';
$output .= $field['after'];
break;
}
case "office":
{
$key = 'officeID';
$field['class'] = isset( $field['class'] ) ? $field['class'] : '';
$field['before'] = isset( $field['before'] ) ? $field['before'] : '
';
$field['after'] = isset( $field['after'] ) ? $field['after'] : '
';
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
$field['label'] = isset( $field['label'] ) ? $field['label'] : '';
$field['blank_option'] = isset( $field['blank_option'] ) ? __( $field['blank_option'], 'propertyhive' ) : __( 'No preference', 'propertyhive' );
$field['multiselect'] = isset( $field['multiselect'] ) ? $field['multiselect'] : false;
if ( $field['multiselect'] )
{
wp_enqueue_script( 'multiselect' );
}
$field['value'] = isset( $field['value'] ) ? $field['value'] : '';
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
{
$field['value'] = (int)$_GET[$key];
}
$output .= $field['before'];
if ($field['show_label'])
{
$output .= '
';
}
$output .= '
';
$output .= $field['after'];
break;
}
case "country":
{
$field['class'] = isset( $field['class'] ) ? $field['class'] : '';
$field['before'] = isset( $field['before'] ) ? $field['before'] : '
';
$field['after'] = isset( $field['after'] ) ? $field['after'] : '
';
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
$field['label'] = isset( $field['label'] ) ? $field['label'] : '';
$field['value'] = isset( $field['value'] ) ? $field['value'] : '';
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
{
$field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
}
$output .= $field['before'];
if ($field['show_label'])
{
$output .= '
';
}
$output .= '
';
$output .= $field['after'];
break;
}
case "slider":
{
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-slider');
wp_enqueue_script('jquery-ui-touch-punch', PH()->plugin_url() . '/assets/js/jquery-ui-touch-punch/jquery.ui.touch-punch.min.js', array('jquery'), '0.2.3', true);
wp_enqueue_style( 'jquery-ui-style', PH()->plugin_url() . '/assets/css/jquery-ui/jquery-ui.css', array(), PH_VERSION );
$field['before'] = isset( $field['before'] ) ? $field['before'] : '
';
$field['after'] = isset( $field['after'] ) ? $field['after'] : '
';
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
$field['label'] = isset( $field['label'] ) ? $field['label'] : '';
$field['min'] = isset( $field['min'] ) ? $field['min'] : '';
$field['max'] = isset( $field['max'] ) ? $field['max'] : '';
$field['step'] = isset( $field['step'] ) ? $field['step'] : '1';
$output .= $field['before'];
if ($field['show_label'])
{
$output .= '
';
}
$output .= '
';
$field_name = str_replace("_slider", "", $key);
$output .= '
';
$output .= '
';
$output .= $field['after'];
$value = '';
$prefix = '';
$suffix = '';
if ( $key == 'price_slider' || $key == 'rent_slider' )
{
$prefix = '£';
$search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' );
$ph_countries = new PH_Countries();
$countries = $ph_countries->countries;
foreach ( $countries as $country_code => $country )
{
if ( isset($country['currency_code']) && $country['currency_code'] == $search_form_currency )
{
if ( $country['currency_prefix'] === true )
{
$prefix = $country['currency_symbol'];
$suffix = '';
}
else
{
$prefix = '';
$suffix = $country['currency_symbol'];
}
break;
}
}
}
$js_key = wp_json_encode( sanitize_html_class( $key ) );
$js_prefix = wp_json_encode( html_entity_decode( $prefix, ENT_QUOTES, 'UTF-8' ) );
$js_suffix = wp_json_encode( html_entity_decode( $suffix, ENT_QUOTES, 'UTF-8' ) );
if ( $field['min'] != '' && $field['max'] != '' )
{
$value = 'values: [ ' . ( isset($_GET['minimum_' . $field_name]) && $_GET['minimum_' . $field_name] != '' ? (float)wp_unslash($_GET['minimum_' . $field_name]) : (float)$field['min'] ) . ', ' . ( isset($_GET['maximum_' . $field_name]) && $_GET['maximum_' . $field_name] != '' ? (float)wp_unslash($_GET['maximum_' . $field_name]) : (float)$field['max'] ) . ' ],';
}
$output .= '';
break;
}
case "hidden":
{
$field['value'] = isset( $field['value'] ) ? $field['value'] : '';
$field['name'] = isset( $field['name'] ) ? $field['name'] : $key;
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
{
$field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
}
$output .= '
';
break;
}
case "html":
{
$field['html'] = isset( $field['html'] ) ? $field['html'] : '';
$field['before'] = isset( $field['before'] ) ? $field['before'] : '
';
$field['after'] = isset( $field['after'] ) ? $field['after'] : '
';
$output .= $field['before'];
$output .= $field['html'];
$output .= $field['after'];
break;
}
case "recaptcha":
{
$field['site_key'] = isset( $field['site_key'] ) ? $field['site_key'] : '';
$output .= '
';
break;
}
case "recaptcha-v3":
{
$field['site_key'] = isset( $field['site_key'] ) ? $field['site_key'] : '';
$output .= '
';
break;
}
case "hCaptcha":
{
$field['site_key'] = isset( $field['site_key'] ) ? $field['site_key'] : '';
$output .= '
';
break;
}
case "turnstile":
{
$field['site_key'] = isset( $field['site_key'] ) ? $field['site_key'] : '';
$output .= '
';
break;
}
case "daterange":
{
wp_enqueue_script( 'moment.js', '//cdn.jsdelivr.net/momentjs/latest/moment.min.js' );
wp_enqueue_script( 'daterangepicker.js', '//cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js' );
wp_enqueue_style( 'daterangepicker.css', '//cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css' );
$field['before'] = isset( $field['before'] ) ? $field['before'] : '
';
$field['after'] = isset( $field['after'] ) ? $field['after'] : '
';
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
$field['label'] = isset( $field['label'] ) ? $field['label'] : '';
$field['value'] = isset( $field['value'] ) ? $field['value'] : '';
$field['style'] = isset( $field['style'] ) ? $field['style'] : '';
$field['class'] = isset( $field['class'] ) ? $field['class'] : '';
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
{
$field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
}
$output .= $field['before'];
if ($field['show_label'])
{
$output .= '
';
}
$output .= '
';
$output .= $field['after'];
break;
}
default:
{
if ( taxonomy_exists($field['type']) )
{
$field['class'] = isset( $field['class'] ) ? $field['class'] : '';
$field['before'] = isset( $field['before'] ) ? $field['before'] : '
';
$field['after'] = isset( $field['after'] ) ? $field['after'] : '
';
$field['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : true;
$field['label'] = isset( $field['label'] ) ? $field['label'] : '';
$field['blank_option'] = isset( $field['blank_option'] ) ? __( $field['blank_option'], 'propertyhive' ) : __( 'No preference', 'propertyhive' );
$field['parent_terms_only'] = isset( $field['parent_terms_only'] ) ? $field['parent_terms_only'] : false;
$field['hide_empty'] = isset( $field['hide_empty'] ) ? $field['hide_empty'] : false;
$field['multiselect'] = isset( $field['multiselect'] ) ? $field['multiselect'] : false;
$field['dynamic_population'] = ( isset( $field['dynamic_population'] ) && $field['type'] == 'location' && $field['parent_terms_only'] === false && $field['multiselect'] === false ) ? $field['dynamic_population'] : false; // only applies to location
if ( $field['multiselect'] )
{
wp_enqueue_script( 'multiselect' );
}
$options = array(
'' => array(
'label' => $field['blank_option'],
'parent' => 0
)
);
$args = array(
'hide_empty' => $field['hide_empty'],
'parent' => 0
);
$args = apply_filters( 'propertyhive_form_taxonomy_terms_args', $args, $field );
$terms = get_terms( $field['type'], $args );
$levels_of_taxonomy = 1;
if ( !empty( $terms ) && !is_wp_error( $terms ) )
{
foreach ($terms as $term)
{
if ( isset($field['hide_empty']) && $field['hide_empty'] === true )
{
$empty_check_args = array(
'post_type' => 'property',
'meta_query' => array(
array(
'key' => '_on_market',
'value' => 'yes',
),
),
'tax_query' => array(
array(
'taxonomy' => $field['type'],
'field' => 'term_id',
'terms' => $term->term_id,
),
),
);
$empty_check_args = apply_filters( 'propertyhive_taxonomy_hide_empty_args', $empty_check_args, $field, $term->term_id );
$empty_check_query = new WP_Query( $empty_check_args );
if ( !$empty_check_query->have_posts() )
{
continue;
}
}
$options[(int)$term->term_id] = array(
'label' => __( $term->name, 'propertyhive' ),
'parent' => 0
);
if ($field['dynamic_population'])
$levels_of_taxonomy = max(1, $levels_of_taxonomy);
if (
!isset($field['parent_terms_only'])
||
(
isset($field['parent_terms_only']) &&
$field['parent_terms_only'] === false
)
)
{
$args = array(
'hide_empty' => $field['hide_empty'],
'parent' => $term->term_id,
);
$args = apply_filters( 'propertyhive_form_taxonomy_terms_args', $args, $field );
$args = apply_filters( 'propertyhive_form_taxonomy_subterms_args', $args, $field );
$subterms = get_terms( $field['type'], $args );
if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
{
foreach ($subterms as $subterm)
{
if ( isset($field['hide_empty']) && $field['hide_empty'] === true )
{
$empty_check_args = array(
'post_type' => 'property',
'meta_query' => array(
array(
'key' => '_on_market',
'value' => 'yes',
),
),
'tax_query' => array(
array(
'taxonomy' => $field['type'],
'field' => 'term_id',
'terms' => $subterm->term_id,
),
),
);
$empty_check_args = apply_filters( 'propertyhive_taxonomy_hide_empty_args', $empty_check_args, $field, $subterm->term_id );
$empty_check_query = new WP_Query( $empty_check_args );
if ( !$empty_check_query->have_posts() )
{
continue;
}
}
$options[(int)$subterm->term_id] = array(
'label' => ( !$field['dynamic_population'] ? '- ' : '' ) . __( $subterm->name, 'propertyhive' ),
'parent' => (int)$term->term_id,
);
if ($field['dynamic_population'])
$levels_of_taxonomy = max(2, $levels_of_taxonomy);
$args = array(
'hide_empty' => $field['hide_empty'],
'parent' => (int)$subterm->term_id
);
$args = apply_filters( 'propertyhive_form_taxonomy_terms_args', $args, $field );
$args = apply_filters( 'propertyhive_form_taxonomy_subsubterms_args', $args, $field );
$subsubterms = get_terms( $field['type'], $args );
if ( !empty( $subsubterms ) && !is_wp_error( $subsubterms ) )
{
foreach ($subsubterms as $subsubterm)
{
if ( isset($field['hide_empty']) && $field['hide_empty'] === true )
{
$empty_check_args = array(
'post_type' => 'property',
'meta_query' => array(
array(
'key' => '_on_market',
'value' => 'yes',
),
),
'tax_query' => array(
array(
'taxonomy' => $field['type'],
'field' => 'term_id',
'terms' => $subsubterm->term_id,
),
),
);
$empty_check_args = apply_filters( 'propertyhive_taxonomy_hide_empty_args', $empty_check_args, $field, $subsubterm->term_id );
$empty_check_query = new WP_Query( $empty_check_args );
if ( !$empty_check_query->have_posts() )
{
continue;
}
}
$options[(int)$subsubterm->term_id] = array(
'label' => ( !$field['dynamic_population'] ? '- - ' : '' ) . __( $subsubterm->name, 'propertyhive' ),
'parent' => (int)$subterm->term_id,
);
if ($field['dynamic_population'])
$levels_of_taxonomy = max(3, $levels_of_taxonomy);
}
}
}
}
}
}
}
if ( $field['dynamic_population'] )
{
wp_localize_script( 'propertyhive_dynamic_population', 'propertyhive_dynamic_population_params', array(
'options' => $options,
'levels_of_taxonomy' => $levels_of_taxonomy,
'value' => isset($_GET[$field['type']]) ? ph_clean($_GET[$field['type']]) : '',
'other_values' => ( isset($_GET['other_' . $field['type']]) && is_array($_GET['other_' . $field['type']]) && !empty($_GET['other_' . $field['type']]) ) ? ph_clean(array_filter($_GET['other_' . $field['type']])) : array(),
'taxonomy' => $field['type'],
) );
wp_enqueue_script( 'propertyhive_dynamic_population' );
}
$field['value'] = isset( $field['value'] ) ? $field['value'] : '';
if ( isset( $_GET[$key] ) && ! empty( $_GET[$key] ) )
{
$field['value'] = sanitize_text_field(wp_unslash($_GET[$key]));
}
for ( $level_i = 1; $level_i <= $levels_of_taxonomy; ++$level_i )
{
$output .= $field['before'];
if ($field['show_label'])
{
$output .= '
';
}
$output .= '
';
$output .= $field['after'];
if ( $field['type'] == 'availability' )
{
$availability_departments = get_option( 'propertyhive_availability_departments', array() );
if ( !is_array($availability_departments) ) { $availability_departments = array(); }
if ( !empty($availability_departments) )
{
?>