【问题标题】:Drupal: How to update database from Select OptionDrupal:如何从选择选项更新数据库
【发布时间】:2015-05-26 21:17:12
【问题描述】:

大家好,我真的是 Drupal 的新手,现在我从我的数据库中选择了我需要的所有数据并将其显示在下拉列表中。 不幸的是,我不知道如何使用这个特定的选定字段更新我的数据库,因为我没有任何价值......

$options = array();
foreach ($results as $result) {
$options["name"] = array(
$result->name,
);
}

$options2 = array();
foreach ($results_tour as $result2) {
$options2[$result2->sku] = array(
$result2->title,
    );
    }

$form['tour'] = array(
'#type' => 'select',
'#options' => $options2,
);

$form['tour_guide'] = array(
'#type' => 'select',
'#title' => t('Tour Guide'),
'#options' => $options,
'#description' => 'Please select a guide for this specific tour'
);

$form['save'] = array(
'#type' => 'submit',
'#value' =>  'Speichern',
'#submit' =>  array('plantours_form_submit'),
);

return $form;

}

function plantours_form_submit($form, $form_state) {

db_update('commerce_line_item')
->fields(array(
'status' => $options["name"]
))
->execute();  
}

【问题讨论】:

    标签: database forms select drupal drupal-7


    【解决方案1】:

    不要手动操作,直接写入数据库,而是使用 Drupal commerce api(我猜你正在使用 drupal commerce):

    https://www.drupal.org/node/1288414

    【讨论】:

      猜你喜欢
      • 2012-12-10
      • 1970-01-01
      • 2016-09-19
      • 1970-01-01
      • 1970-01-01
      • 2014-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多