大佬教程收集整理的这篇文章主要介绍了php – Codeigniter检查复选框值,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
但是在我的代码中,无论是否检查,当我点击UPDATE按钮时,它会不断删除照片,我想知道为什么会这样?
有人可以通过我的代码并给出建议吗?
控制器:
$user_id = $this->session->userdata('user_id'); $profile = $this->users->get_profile_by_id($user_id); if(!empty($_FILES['photo']['name'])) { //image upload process } else { $checked = $this->input->post('remove'); if(isset($checked) == 1) { $photo_to_table = ''; // here will do remove process to delete file in directory } else { $photo_to_table = $profile->photo; } } if($this->form_validation->run()) { // validation ok if(!is_null($data = $this->tank_auth->update_user( $this->form_validation->set_value('name'),$this->form_validation->set_value('country'),$this->form_validation->set_value('website'),$photo_to_table ))) { // success $this->session->set_flashdata('msg','Profile has been updated'); redirect(current_url()); } }
视图:
<?PHP echo form_open_multipart($this->uri->uri_string()); ?> <table border="0"> <?PHP if(!empty($uphoto)){ ?> <tr> <td> <div> <img src="<?PHP echo base_url().$userpath.$uphoto; ?>" /> </div> <div> <input id="remove" type="checkBox" name="remove"> <label for="remove">Remove photo</label> </div> </td> </tr> <?PHP } ?>
谢谢.
if(isset($checked) == 1){
至
if((int) $checked == 1){
原因是变量$checked将始终设置其值是否为1. $checked = $this-> input-> post(‘remove’);如果未在POST数据中设置’remove’,则返回NULL.
以上是大佬教程为你收集整理的php – Codeigniter检查复选框值全部内容,希望文章能够帮你解决php – Codeigniter检查复选框值所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。