开发者

ajax is not working in drupal 7 while using edit section

I'm also using drupal-7 and create a module. A form in which there are 2 drop downs. On selection of car model (1st drop down) car variant (2nd drop down) value will change. It work perfectly when I am creating new one. But once I go to edit some value it shows me error.

========================================================开发者_开发百科===================

An AJAX HTTP error occurred.

HTTP Result Code: 500

Debugging information follows.

Path: /vehicle_ades/?q=system/ajax

StatusText: Service unavailable (with message)

ResponseText: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ajax' in 'where clause':

SELECT heading,details,value_of_offer,exchange_offer,total_savings,car_model_id,car_variant_id FROM {va_offer} where id = ajax; Array ( )

===========================================================================

How do I pass car model id to ajax function


I'm working on drupal 7. Below is the code. What I have done is on selection of car model car variant will change and the data save in the table.

function add_offer_form($form, $formstate) {

$form['add_offer_new_car_model'] = array(

'#type' => 'select',
'#required' => TRUE,
'#options' => $car_model,
'#ajax' => array(
    'effect' => 'fade',
    'progress' => array('type' => 'none'),
    'callback' => 'variant_callback',
    'wrapper' => 'replace_variant',
),

);

// Combo box to select new car variant

$form['add_offer_new_car_variant'] = array(

'#type' => 'select',
'#options' => array(),
// The prefix/suffix provide the div that we're replacing, named by #ajax['wrapper'] above.
'#prefix' => '<div id="replace_variant">',
'#suffix' => '</div>',

);

// An AJAX request calls the form builder function for every change.

// We can change how we build the form based on $form_state.

if (!empty($formstate['values']['add_offer_new_car_model'])) {

$model_id = $formstate['values']['add_offer_new_car_model'];
$rows = array();
$result = db_query("SELECT id, variant_name from {va_car_variant} where car_model_id in ($model_id,1) order by variant_name");
while ($data = $result->fetchObject()) {
    $id = $data->id;
    $rows[$id] = $data->variant_name;
}
$form['add_offer_new_car_variant']['#options'] = $rows;

}

}

//////////////////////////////////////////////////////// ///////// FUNCTION FOR AJAX CALL BACK

function variant_callback($form, &$form_state) {

return $form['add_offer_new_car_variant'];

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜