0

I'm writing a custom module to obtain an online quote.

The form has an additional button and once it is clicked, a database query runs and print a value.

//My code for custom button
function garden_form_alter( &$form, &$form_state,$form_id ){
if ($form_id == 'webform_client_form_4208') {
$form['actions']['garden_quote']  = array(
    '#type' => 'submit',
    '#value' => t('Get online estimate'),
    '#submit' => array('mymodule_custom_submit'),
);
$form['#validate'][] = 'mymodule_custom_validate'; 
}
}

//Custom submit handler
function mymodule_custom_submit($form, &$form_state) {
$query = db_select('gardenvalue', 'f');
$query->fields('f', array('total_cost'))
    ->condition('meters', '2', '=');
$result = $query->execute();
dpm($result);
}

Once the form has been submitted dpm shows the 'meters' value as'db_condition_placeholder_0' and not number 2. What can be the reason?

Also I would like to show the $result value on a new text field once the form reloads. If we assume this new text field key is 'total_garden' how can I change its' value to $result on form reload?

Thanks in advance!

0
//My code for custom button
function garden_form_alter(&$form, &$form_state, $form_id ){
    if ($form_id == 'webform_client_form_4208') {
        $form['actions']['garden_quote']  = array(
            '#type' => 'submit',
            '#value' => t('Get online estimate'),
            '#submit' => array('garden_custom_submit'),
        );
        $form['#validate'][] = 'garden_custom_validate'; 
    }
}

//Custom submit handler
function garden_custom_submit($form, &$form_state) {
    $query = db_select('gardenvalue', 'f');
    $query->fields('f', array('total_cost'))
        ->condition('f.meters', 2, '=');
    $result = $query->execute();
    dpm($result);
}

You have spacing errors and identation errors, the condition is not pointing to a field in the table, and you have to dig into the results array to extract the value, as far as I know you only can print results in a form with

drupal_set_message(t('your message', 'success'); instead of dpm hope this help you a little bit...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.