Get user list according to node field value I have created one content type named "Project". I have added one field in it named "Skills". Skills is a multiple select field. And I have added one submit button. Which I want to use to get records of users. I have created an Ajax form submit, but my issue now is that I can't alter the form after the Ajax submit. 

This is the code I'm currently using:

function MYMODULE_form_alter(&amp;$form, $form_state, $form_id) {

  if ($form_id == 'project_node_form') {

    $form['field_user_lists']['#access'] = FALSE;

    // Provide a submit button.
    $form['submit'] = [
      '#type'   =&gt; 'submit',
      '#value'  =&gt; 'Get Employee',
      '#weight' =&gt; '4',
      '#ajax'   =&gt; [
        'callback' =&gt; 'MYMODULE_form_ajax_submit',
        'wrapper'  =&gt; 'project_node_form',
        'method'   =&gt; 'replace',
        'effect'   =&gt; 'fade',
      ],
    ];

    $form['actions']['submit']['#submit'][] = '_custom_form_submit';
  }
}

function MYMODULE_form_ajax_submit($form, &amp;$form_state) {

  if (!empty($form_state['input']['field_skills']['und'])) {

    //print_r($form_state['input']['field_skills']['und']); die();
    $query = db_select('field_revision_field_skillss', 'n');

    $query-&gt;join('users', 'u', 'n.entity_id = u.uid'); //JOIN node with users
    $query-&gt;groupBy('u.uid');//GROUP BY user ID
    $query-&gt;fields('u', ['uid', 'name'])//SELECT the fields from node
    -&gt;condition('n.field_skillss_tid', $form_state['input']['field_skills']['und'], 'IN');

    $result = $query-&gt;execute();

    $form['field_user_lists']['#access'] = TRUE;

    while ($record = $result-&gt;fetchAssoc()) {
      print_r($record['name']);
    }
  }
  else {
    $output = 'Enter a value';
  }
}
I think you are getting close. When you use ajax in Drupal, you have to return a render array with commands. In your case it looks like you would want ajax_command_replace. 

Two additional steps should get you up and running.

First, built an html string instead of using print_r to try and send content back to the client. 

    $return_html = '&lt;div class="myclass"&gt;';    
    while ($record = $result-&gt;fetchAssoc()) {
              $return_html.='&lt;div class="my_user"&gt;' . $record['name'] . '&lt;/div&gt;';
            }
    $return_html .= '&lt;/div&gt;';


Then create the ajax object and render array to send back to the client

 $commands[] = ajax_command_replace('#my_selector', 'some html here');
 return array(
      '#type' =&gt; 'ajax',
      '#commands' =&gt; $commands,
    );


In this example, you would need to have a div on your page with an id of 'my_selector' that would receive the new html.