duanbi1888 2014-05-24 13:57
浏览 42
已采纳

表单codeigniter上的两个不同的提交按钮表现得很奇怪

I have two buttons on one submit form but when I post the submit button it returns nothing;"ABOUT THE BUTTON"; the other data is retrieved WELL.

I have been using different names for the submit button but nothing works.. Could someone help me? thank you. The FORM data is retrieved well but not the submit button value? i need the value to differ the condition

controller: admin.php

        function submit_unitgroupwd(){
        $this->access_chk(); //CHECK USER ACCESS

    $sbm=$this->input->post('sbm'); // returns NOTHING
   echo $_POST["sbm"]; // returns undefined index sbm
   echo $_POST['sbm']; // returns undefined index sbm
var_dump($_POST); // returns all the post data bt the submit button

 //echo var_dump($this->input->post("sbm"));
exit();

if($this->input->post('sbm') == "Update") { 
// do update
} else {
// do delete
}

}

view:

 echo "<form action=".site_url("admin/submit_unitgroupwd")." method=post id=form>"; 
echo "<div style='float:left;color:red;' id='res'></div>";
?><?php 
foreach($q1->result_array() as $r1){
$bankname= substr($r1["bank"],0,3);
//echo $bankname;


echo "<input type=hidden name=dgroup value='".$dgroup."'>";
echo "<tr>";
echo "<td width=20% colspan=3 style='font-size: 16px;'>".strtoupper($r1["bank"])."</td>";
echo "</tr>";
echo "<tr>";
echo "<td width=100>".$group_[0]."</td>";
echo "<td><input type=text name='$bankname-utama' value='".str_replace(" ","",$r1["utama"])."' style='width: 100%;'></td>";

if ($r1["bank"] == 'ALL'){
    echo "<td rowspan='1'><br><input type='checkbox' name='cek[]' id='cek[]' value='$bankname' ></td>";

    echo "<input type=hidden name=_code$bankname value='".$r1["bank"]."'>";
    echo "</tr>";
    echo "</tr>";
    continue;
}

echo "<td rowspan=".($dgroup + 1)."><br><input type='checkbox' name='cek[]' id='cek[]' value='$bankname' ><br><br><br><br><br><br><br>";
echo "<input type=hidden name=_code$bankname value='".$r1["bank"]."'>";

echo "</tr>";

$_alp = "a";
for ($_g=0; $_g<$dgroup; $_g++){
    echo "<tr>";
    echo "<td width=100>".$group_[($_g + 1)]."</td>";
    echo "<td width=80%><input type=text name='$bankname-wd$_alp' value='".str_replace(" ","",$r1["wd$_alp"])."' style='width: 100%;'></td>";
    echo "</tr>";
    $_alp++;
echo "</tr>";

}
}
?>
>
<input type="submit" class="button" value='Update' name="sbm"/>
<input type="submit" class="button" value='Delete' name="sbm"/>
  • 写回答

2条回答 默认 最新

  • duanaozhong0696 2014-05-24 15:10
    关注

    You could simply use only the

     <input type="submit" class="button" value='Update' name="sbm"/> 
    

    and use an anchor for the delete action,

    echo "<a href ='controller_delete/$item_id' class='button'>Delete</a>
    

    since you normally wont need other inputs on the delete action if you get my point.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?