Add extra button on webform and Ajaxify I'm building a form similar to attached image.


Customer enters values for all 3 text fields and click 'Get Online quote'. This will perform a database query (using AJAX) and display a value just below 'Get Online quote' button.

If he's happy with the quote, can ask to get contacted by clicking the second button, 'Contact me for more details'. Therefore second button act as the form submit button which will redirect to a thank you page.

So far I have coded like below.

// online quote button
function fence_quote_form_alter( &amp;$form, &amp;$form_state,$form_id ){
  if ($form_id == 'webform_client_form_4208') {
    $form['actions']['fence_quote']  = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Get online estimate'),
    '#submit' =&gt; array('fence_quote_custom_submit'),
    '#ajax' =&gt; array(
      'callback' =&gt; 'fence_quote_form_callback', 
      'wrapper' =&gt; 'fence_quote-submit-button', 
    ),
  );
    $form['#validate'][] = 'fence_quote_custom_validate';
  }
}

function fence_quote_custom_validate($form, &amp;$form_state) {
  // your validation code
}


function fence_quote_custom_submit($form, &amp;$form_state) {
  $query = db_select('fence_900', 'f');
  $query-&gt;fields('f', array('total_cost'));
        -&gt;condition('meters', 2, '=');
  $result = $query-&gt;execute();
}

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

}



I'm unclear on what to put under AJAX callback function. Should I
have the database query in it instead of putting inside custom submit
function?
How can I display the database query value below the 'online quote' button on a new text field? I'm unable to print using $form_state['values']['total']
Db Query in Ajax callback. I would suggest to change type of Ajax-Button from submit to button.
In callback return instead of print. You should also use -&gt;fetchAll() for instance after -&gt;execute()