我试图在 cakephp 表单中获取输入数据的值,以便我可以在 sql 查询中使用它来自动填充其他数据。目前我正在尝试使用 $this->request->data 但是当我改变我的客户时它没有显示任何结果。我希望它显示所选的客户,但目前它只是空白。不确定我是在尝试正确获取数据还是在错误地显示数据。
<div class="invoices form large-9 medium-8 columns content">
<?= $this->Form->create($invoice) ?>
<fieldset>
<legend><?= __('Add Invoice') ?></legend>
<?php
echo $this->Form->input('customer_id', ['options' => $customers, 'empty' => true,'id'=>'customers']); ?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
<script>
document.getElementById('customers').addEventListener('change',function(){
alert(<?php echo $this->request->data('customers');
?>)
});
</script>
最佳答案
用这个替换你的代码
document.getElementById('customers').addEventListener('change',function(){
alert(this.value);
});
关于javascript - CakePHP 从表单中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47324876/