【发布时间】:2015-09-02 18:58:24
【问题描述】:
您好,我想扣除经销商的余额。每个经销商都有自己的用户,因此他可以编辑他的用户。现在,如果经销商设置用户余额 = 是,那么我想从他的帐户中扣除 5 欧元。那么我如何知道单选按钮的值是否从“否”更改为“是”?
<tr>
<td>Balance</td>
<td>Yes<?php echo form_radio('balance','Yes', $this->input->post('balance') ? $this->input->post('balance') : $user->balance); ?> No <?php echo form_radio('balance','No', $this->input->post('balance') ? $this->input->post('balance') : $user->balance); ?></td>
</tr>
所以现在登录后,如果经销商将用户余额设置为“是”,则应扣除 5 欧元!请帮我解决这个问题:
用户控制器:
public function edit ($id = NULL)
{
$usertype=$this->session->userdata('usertype');
if($usertype ==="reseller")
{
// Fetch a user or set a new one
if ($id) {
$this->data['user'] = $this->user_m->get($id);
count($this->data['user']) || $this->data['errors'][] = 'User could not be found';
}
else {
$this->data['user'] = $this->user_m->get_new();
}
// Set up the form
$rules = $this->user_m->rules_admin;
$id || $rules['password']['rules'] .= '|required';
$this->form_validation->set_rules($rules);
// Process the form
if ($this->form_validation->run() == TRUE) {
$data = $this->user_m->array_from_post(array('sip_id','sip_pass','name','email', 'password','phone','status','created','balance'));
$data['password'] = $this->user_m->hash($data['password']);
$selected_radio=$_POST['yes'];
if($selected_radio=='checked')
{
$this->reseller_m->deduct();
}
$this->user_m->save($data, $id);
redirect('reseller/user');
}
// Load the view
$this->data['subview'] = 'reseller/user/edit';
$this->load->view('reseller/_layout_main', $this->data);
}
else{
$this->load->view('permission');
}
}
我试过这个:
$selected_radio=$_POST['yes'];
if($selected_radio=='checked')
{
$this->reseller_m->deduct();
}
【问题讨论】:
-
为单选按钮设置隐藏字段并在值更改时更改该隐藏值。通过隐藏按钮的值,您将知道值是否发生变化
-
您肯定想只使用 PHP 来实现吗?因为你不能使用 PHP 处理 DOM。为此,您需要 Javascript。
-
@Affan 你能写下示例代码吗?
-
@AnandGhaywankar 是的,我想我需要 javascript,但我不知道该怎么做。
-
类似
if ($_POST['balance'] == "Yes")?发布 DOM 输出和网络输出。
标签: php codeigniter