Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查PHP CodeIgCenter中单选按钮的值是否更改?_Php_Codeigniter - Fatal编程技术网

如何检查PHP CodeIgCenter中单选按钮的值是否更改?

如何检查PHP CodeIgCenter中单选按钮的值是否更改?,php,codeigniter,Php,Codeigniter,您好,我想扣除经销商的余额。每个经销商都有自己的用户,因此他可以编辑自己的用户。现在,如果经销商设置用户余额=是,那么我想从他的帐户中扣除5欧元。那么我如何知道单选按钮的值是否从“否”更改为“是” <tr> <td>Balance</td> <td>Yes<?php echo form_radio('balance','Yes', $this->input->post('balance') ? $this->inpu

您好,我想扣除经销商的余额。每个经销商都有自己的用户,因此他可以编辑自己的用户。现在,如果经销商设置用户余额=是,那么我想从他的帐户中扣除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>
我试过这个:

$selected_radio=$_POST['yes']; 
                                    if($selected_radio=='checked')
                                    { 
                                        $this->reseller_m->deduct();
                                    } 


您可以通过以下方式检查所选单选按钮:

<?php 
$selected_radio=$_POST['yes']; 
if($selected_radio=='checked'){ 
//deduct 5 euros;
} 
?>

您可以使用以下代码获取单选按钮的值:

$this->input->post('balance')

现在,您可以在后端执行简单的检查:

if ($this->input->post('balance') === 'Yes'){
  //execute when true
} else{
  // execute other action
}
当您想要获取一个单选按钮的值且名称相同时(当您有多个单选按钮时),您可以使用
$\u POST['name of radiobutton']

例子 //HTML

<input type="radio" name="example" value="1" />
<input type="radio" name="example" value="2" />

设置单选按钮的隐藏字段,并在值更改时更改该隐藏值。通过隐藏按钮值,您将知道值是更改还是不更改。您肯定只想使用PHP来实现这一点吗?因为您无法使用PHP处理DOM。你需要Javascript。@阿凡,你能写下一个示例代码吗?@AnandGhaywankar是的,我想我需要Javascript,但我不知道怎么做。类似于
if($\u POST['balance']==“yes”)
?发布DOM输出和网络输出。从逻辑上讲,我发现您的答案正确,但在PHP CodeiCenter中没有与我一起工作。请检查更新的问题,我在其中添加了我的用户控制器代码
$\u Post['yes']
将是未定义的,
$selected\u radio
值将永远不会被
检查
还有一件事我有许多经销商和许多用户。所以,这将更新所有用户,或者我可以做一些事情,只更新那些经销商的用户被编辑!
<input type="radio" name="example" value="1" />
<input type="radio" name="example" value="2" />
$this->input->post('example'); // will be 1 or 2