',
'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,
'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'][0];
}
}
}
$args = array(
'hide_empty' => false,
'parent' => 0
);
$terms = get_terms( 'location', $args );
$options = array();
$selected_value = '';
if ( !empty( $terms ) && !is_wp_error( $terms ) )
{
$options = array( '' => __( 'All Locations', 'propertyhive' ) );
foreach ($terms as $term)
{
$options[$term->term_id] = $term->name;
$args = array(
'hide_empty' => false,
'parent' => $term->term_id
);
$subterms = get_terms( 'location', $args );
if ( !empty( $subterms ) && !is_wp_error( $subterms ) )
{
foreach ($subterms as $term)
{
$options[$term->term_id] = '- ' . $term->name;
}
}
}
}
if ( !empty($options) )
{
$fields['location'] = array(
'type' => 'select',
'label' => __( 'Location', 'propertyhive' ),
'required' => false,
'options' => $options,
);
if ( is_user_logged_in() && isset($applicant_profile['locations']) && is_array($applicant_profile['locations']) && !empty($applicant_profile['locations']) )
{
$fields['location']['value'] = $applicant_profile['locations'][0];
}
}
$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['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['show_label'] = isset( $field['show_label'] ) ? $field['show_label'] : false;
$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 .= '
';
}
foreach ( $field['options'] as $option_key => $value )
{
$output .= '
';
}
$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') && 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['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 "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;
}
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'] : __( 'No preference', 'propertyhive' );
$field['parent_terms_only'] = isset( $field['parent_terms_only'] ) ? $field['parent_terms_only'] : false;
$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]));
}
$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) )
{
?>