How to exposed custom profile fields in views The custom fields were created using a custom form in a module, not user entities or Profile2.

How can I expose these fields to views? My goal is to allow an admin to filter users by exposing those custom fields.

Here's the function that creates the custom profile form:

function mymodule_profile_form($form, &amp;$form_state, $account) {
[...]
//
// Basic Info
//
$form['fs_basic'] = array(
  '#title' =&gt; 'Basic Info',
  '#type' =&gt; 'fieldset',
  '#prefix' =&gt; '&lt;div class="row"&gt;',
);

$form['fs_basic'][SOME_SF_CONTACT_FIRSTNAME] = array(
  '#title' =&gt; 'First Name',
  '#type' =&gt; 'textfield',
  '#default_value' =&gt; $contact[SOME_SF_CONTACT_FIRSTNAME],
 );
$form['fs_basic'][SOME_SF_CONTACT_LASTNAME] = array(
  '#title' =&gt; 'Last Name',
  '#type' =&gt; 'textfield',
  '#default_value' =&gt; $contact[SOME_SF_CONTACT_LASTNAME],
);
$form['fs_basic'][SOME_SF_CONTACT_MIDDLENAME] = array(
  '#title' =&gt; 'Middle Name',
  '#type' =&gt; 'textfield',
  '#default_value' =&gt; $contact[SOME_SF_CONTACT_MIDDLENAME],
);
$form['fs_basic'][SOME_SF_CONTACT_SUFFIX] = array(
  '#title' =&gt; 'Suffix',
  '#type' =&gt; 'textfield',
  '#default_value' =&gt; $contact[SOME_SF_CONTACT_SUFFIX],
);
//
// Profile Info
//
$form['fs_profile'] = array(
  '#title' =&gt; 'Profile',
  '#type' =&gt; 'fieldset',
  '#prefix' =&gt; '&lt;div class="row"&gt;',
);
$form['fs_profile']['name'] = array(
  '#title' =&gt; 'Username',
  '#type' =&gt; 'textfield',
  '#default_value' =&gt; $account-&gt;name,
  '#maxlength' =&gt; 20,
);
[...] 
$form['submit'] = array(
  '#value' =&gt; 'Submit',
  '#type' =&gt; 'submit',
  '#attributes' =&gt; array('class' =&gt; array('btn btn-primary align-left push-
down')),
);

$form['#validate'][] = 'user_account_form_validate';
$form['#validate'][] = 'user_validate_picture';
$form['#validate'][] = 'user_profile_form_validate';
$form['#validate'][] = 'mymoduler_profile_form_validate';
$form['#submit'][] = 'mymodule_profile_form_submit';
// Add the final user profile form submit handler.
$form['#submit'][] = 'user_profile_form_submit';

  return $form;
}


I want to be able to expose the Last Name in Views to I can allow an admin to search.
In order to use it with Views, one of the following have to be true:


You are using Profile2
You are using core User profile
You are using actual fields from Field API
The profile storage is an entity
None of the above, and you are using a custom table


One of these should let you add a relationship in Views from 'User' to 'Profile2' associated to that user, if not, the core profile fields should be available.

However, if you used a custom table, you will have to do some legwork describing your data to Views in order for it to be an option.

Here are some resources that will help you in that direction:


How to add relationship in view for custom entity
hook_views_data
https://groups.drupal.org/node/400598
http://www.zyxware.com/articles/3280/drupal-how-to-add-view-relationships-programmatically-with-custom-database-tables-in-drupal-7


Do know that just because they are 'fields' in a custom form does not mean that it is represented in Drupal the same way. As far as Drupal knows (and from what I see in the provided code) it is your standard form made with FormAPI. They are not really "custom fields" so much as form items abstracting the input to store data.