2 回答
TA贡献1828条经验 获得超3个赞
让我们从一些问题开始。
您
id
在多个元素上有相同的内容。id
's'在文档中必须是唯一的。您
name
在两个选择上都有相同的选择,这将使一个在表单发布时覆盖另一个
因此,让我们从更改名称和 ID 开始:
<!-- The personal select -->
<select class="form-group loan_amount" id="loan_amount_personal" name="loan_amount_personal" required>
<!-- The business select -->
<select class="form-group loan_amount" id="loan_amount_business" name="loan_amount_business" required>
如果有的话,您可能需要用新的 id 更新 javascript 中的任何引用。
然后,当表单发布时,您会根据类型获得所需的选择:
$amount = null;
if ($this->input->post('loan_type') === 'Personal') {
$amount = $this->input->post('loan_amount_personal');
} else {
$amount = $this->input->post('loan_amount_business');
}
// Or for short:
$amount = $this->input->post('loan_type') === 'Personal'
? $this->input->post('loan_amount_personal')
: $this->input->post('loan_amount_business');
然后,在构建数组时:
'loan_type' => $this->input->post('loan_type'),
'loan_amount' => $amount,
- 2 回答
- 0 关注
- 142 浏览
添加回答
举报