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( &$form, &$form_state,$form_id ){
if ($form_id == 'webform_client_form_4208') {
$form['actions']['fence_quote'] = array(
'#type' => 'submit',
'#value' => t('Get online estimate'),
'#submit' => array('fence_quote_custom_submit'),
'#ajax' => array(
'callback' => 'fence_quote_form_callback',
'wrapper' => 'fence_quote-submit-button',
),
);
$form['#validate'][] = 'fence_quote_custom_validate';
}
}
function fence_quote_custom_validate($form, &$form_state) {
// your validation code
}
function fence_quote_custom_submit($form, &$form_state) {
$query = db_select('fence_900', 'f');
$query->fields('f', array('total_cost'));
->condition('meters', 2, '=');
$result = $query->execute();
}
function fence_quote_form_callback($form, &$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']