Php 给提交按钮一个值代码点火器
我想给我的提交按钮一个值。我看了这个视频, 但我正在使用CodeIgniter,所以它给了我一个错误 我已经这样做了:Php 给提交按钮一个值代码点火器,php,codeigniter,submit,codeigniter-3,Php,Codeigniter,Submit,Codeigniter 3,我想给我的提交按钮一个值。我看了这个视频, 但我正在使用CodeIgniter,所以它给了我一个错误 我已经这样做了: <?php echo form_open('Mycontroller/thisfunction/'.$this->uri->segment(3)); ?> <button class="btn btn-info fa fa-save" type="submit" name ="1">  Save&l
<?php
echo form_open('Mycontroller/thisfunction/'.$this->uri->segment(3));
?>
<button class="btn btn-info fa fa-save" type="submit" name ="1">  Save</button>
<button class="btn btn-primary fa fa-save" type="submit" name ="2">  Save1</button>
<?php
echo form_close();
?>
但是我得到了错误的消息:未定义的偏移量:1
和消息:未定义的偏移量:2
我需要此代码,因为我将像这样使用它:
if(THIS BUTTON IS USED){
redirect it to this page
}else if(THIS BUTTON IS USED){
redirect it to other page
}
在控制器中
public function thisfunction(){
if( isset($_POST['1']) ){
echo "1";
} else {
//else if not needed, if not '1' it has to be '2'
echo "2";
}
}
首先,您需要检查它是否已设置 例如
显然,
$\u POST['1']
正在查看POST数组中的项目1,而不是名为“1”
的项目。那么,当您使用字母代替数字作为名称时会发生什么?
public function thisfunction(){
if( isset($_POST['1']) ){
echo "1";
} else {
//else if not needed, if not '1' it has to be '2'
echo "2";
}
}
$formdata = $this->input->post();
if(isset($formdata['1'])){
echo "1";
}
else{
echo "2"
}