Ajax button doesn't work I followed this tutorial:
https://rapiddg.com/blog/creating-ajax-callback-user-reference-fields

to create a button to fill some field in a form with the values of the current user.

Here the cose I added to my hoo_form_alter:

if ($form_id == 'datore_node_form')
{
global $user;
  $form['title']['#type'] = 'hidden';
  $form['title']['#value'] = 'test';

$form['user_replace'] = array(
    '#title' =&gt; t("User Information"),
    '#prefix' =&gt; '&lt;div id="datore_node_form_group_cs"&gt;',
    //name of the node form (already existing, if you're modifying an existing node form)
    '#suffix' =&gt;'&lt;/div&gt;',

    $form['user_replace']['user_copy'] = array(
      '#type' =&gt; 'button',
      '#value' =&gt; 'Sono io il datore!',
      '#ajax' =&gt; array(
        'event'=&gt;'click',
        'callback' =&gt;'user_replace_ajax_callback',
        'wrapper' =&gt; 'datore_node_form_group_cs',
      ),
    ),
  );

 $form['user_replace']['field_cognome'] = $form['field_cognome'];
  unset($form['field_cognome']);

  $user = user_load($user-&gt;uid);
  dpm($user);
  dpm($user-&gt;field_cognome['und'][0]['value']);
  dpm($form);
  dpm($form_state);

  if (!empty($form_state['values']['field_cognome']))
  {
    unset($form_state['input']['field_cognome']['und'][0]['value']);
    $form_state['input']['field_cognome']['und'][0]['value'] = $user-&gt;field_cognome['und'][0]['value'];
    return $form;
  }

  function user_replace_ajax_callback($form, &amp;$form_state)
  {
    ajax_command_alert("hello"); // doesn't work
    return $form['user_replace'];
  }


but if I click the button nothing happen.
Any advise?
The only thing you are doing with your code is replacing the button that you are clicking. It's probably getting replaced, but visually will look exactly the same as it did before, which is why it appears nothing is happening.