【发布时间】:2018-10-05 10:09:22
【问题描述】:
我有这张桌子:
客户[id, name, surname, phone, text, balance, created]
service_types[id, title, price, length, is_subscription, created]
customer_service_types[id, customer_id, service_type_id, price, created]
在 CustomerServiceTypes 的 add.ctp 中,我有一个包含服务类型的下拉菜单和一个包含价格的字段。我想要的是当用户从下拉列表中选择服务类型,然后使用所选服务类型的price 更新价格字段。
这是现有的代码:
add.ctp
<fieldset>
<legend><?= __('Add Customer Service Type') ?></legend>
<?php
echo $this->Form->control('customer_id', ['options' => $customers]);
echo $this->Form->control('service_type_id', ['options' => $serviceTypes]);
echo $this->Form->control('price');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
CustomerServiceTypesController.php(添加功能)
public function add()
{
$customerServiceType = $this->CustomerServiceTypes->newEntity();
if ($this->request->is('post')) {
$customerServiceType = $this->CustomerServiceTypes->patchEntity($customerServiceType, $this->request->getData());
if ($this->CustomerServiceTypes->save($customerServiceType)) {
$this->Flash->success(__('The customer service type has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The customer service type could not be saved. Please, try again.'));
}
$customers = $this->CustomerServiceTypes->Customers->find('list', ['limit' => 200]);
$serviceTypes = $this->CustomerServiceTypes->ServiceTypes->find('list', ['limit' => 200]);
$this->set(compact('customerServiceType', 'customers', 'serviceTypes'));
}
【问题讨论】:
-
你有没有尝试做任何事??
-
@Exterminator nope 不知道如何开始,可能需要javascript?
标签: javascript php ajax cakephp cakephp-3.6