How to fetch form state value of a form on clicking custom button? How to fetch form state value of a form on clicking custom mobile verification(required field in register form) button ajax based suppose I want to show mobile number(Form_state value) of form on clicking ajax based button named mobile verification. Here's the code:

 if($form_id == 'user_register_form')
 {

        $form['mybutton'] = array(
        '#type' =&gt; 'button',
        '#name' =&gt; 'mybutton',
        '#value' =&gt; 'Mobile Verification',
        '#title' =&gt; t('Mobile Verification'),
        //'#submit' =&gt; array('my_ajax_callback'),
        '#prefix' =&gt; '&lt;div id="dialog" title="Dialog Title" style="display:none;"&gt;&lt;span class="close"&gt;X&lt;/span&gt;&lt;div &gt;&lt;form action="#"&gt;
                        Enter OTP&lt;br&gt;
                        &lt;input type="text" class="otp" name="otp" value=""&gt;
                        &lt;br&gt;
                        &lt;input type="submit" class="otp_submit" value="Submit"&gt;
                        &lt;/form&gt; &lt;/div&gt;&lt;/div&gt;',
        '#weight' =&gt; 19,
        '#ajax' =&gt; array(
                'event' =&gt; 'click',
                'callback' =&gt; 'my_ajax_callback',
                'method' =&gt; 'replace',                  
                'wrapper' =&gt; 'form-wrapper',
          ),
        );


}

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

     echo '&lt;pre&gt;';      
     print_r($form_state);  
     die;
   // return $form;
 }  


In short i just want without saving form data can we show form_state value on clicking ajax based button in popup form.

The above code not working for me not able to get form_state value
In that case, you can create a container in the form, and fill it with the values after AJAX has been fired. Then you only need to return that container in your ajax callback.

if($form_id == 'user_register_form')
{
  $form['mybutton'] = array(
    // ...
    '#ajax' =&gt; array(
      'callback' =&gt; 'my_ajax_callback',
      'wrapper' =&gt; 'form_state_values_wrapper',
    ),
  );

  $form['form_state_values'] = array(
    '#prefix' =&gt; '&lt;div id="form_state_values_wrapper"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#markup' =&gt; '',
  );

  if(isset($form_state_, $form_state['values']))
  {
    $form['form_state_values']['#markup'] = '&lt;pre&gt;' . print_r($form_state['values'], TRUE) . '&lt;/pre&gt;',
  }

}

function my_ajax_callback(&amp;$form, &amp;$form_state,$form_id) {
  return $form['form_state_values'];
}