Dilukshan Mahendra
Dilukshan Mahendra

Reputation: 3398

PHP Submit button not responding (Codeigniter)

I have the following view (home_view.php)

<?php $this->load->helper('url'); 


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>diluks eCommerce - Home</title>
      <link href="<?php echo base_url();?>Public/scripts/style.css" rel="stylesheet" type="text/css" />
   </head>
   <body>
   <form action="<?php echo base_url();?>index.php/welcome_controller" method="post">
      <div class="container">
          <?php 
$userpermission = $this->session->userdata('userpermission');

if($userpermission==1){
   include 'header-admin.php'; 
}
else if($userpermission==2){
   include 'header-user.php'; 
}
else{
include 'header-guest.php';}

 ?>
         <div class="level3 clearfix">
            <?php include 'shopping-sidebar.php'; ?>
            <div class="body-content">

               <div class="image-slider">
                  <img src="<?php echo base_url();?>Public/img/main-img.png" width="785" height="220" />
               </div>
               <div class="seperate-space">
                  <div class="separate-title"><a class="bold-captions">Latest Picks</a>
                  </div>
               </div>
               <div class="items">
                  <div class="item-holder">
                     <table align="center" width="256px" cellpadding="0px" cellspacing="0px">
                        <tr>
                           <td class="item-info" align="center" height="34px">Item name</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="230px">
                              <img src="<?php echo base_url();?>Public/img/sunflowers.png" width="256" height="230" />
                           </td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="34px">$30</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
                        </tr>
                     </table>
                  </div>
                  <div class="item-holder">
                     <table align="center" width="256px" cellpadding="0px" cellspacing="0px">
                        <tr>
                           <td class="item-info" align="center" height="34px">Item name</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="230px">
                              <img src="<?php echo base_url();?>Public/img/treecard.png" width="256" height="230" />
                           </td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="34px">$30</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
                        </tr>
                     </table>
                  </div>
                  <div class="item-holder">
                     <table align="center" width="256px" cellpadding="0px" cellspacing="0px">
                        <tr>
                           <td class="item-info" align="center" height="34px">Item name</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="230px">
                              <img src="<?php echo base_url();?>Public/img/3-flowers.png" width="256" height="230" />
                           </td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="34px">$30</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
                        </tr>
                     </table>
                  </div>
                  <div class="item-holder">
                     <table align="center" width="256px" cellpadding="0px" cellspacing="0px">
                        <tr>
                           <td class="item-info" align="center" height="34px">Item name</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="230px">
                              <img src="<?php echo base_url();?>Public/img/sunflowers.png" width="256" height="230" />
                           </td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="34px">$30</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
                        </tr>
                     </table>
                  </div>
                  <div class="item-holder">
                     <table align="center" width="256px" cellpadding="0px" cellspacing="0px">
                        <tr>
                           <td class="item-info" align="center" height="34px">Item name</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="230px">
                              <img src="<?php echo base_url();?>Public/img/treecard.png" width="256" height="230" />
                           </td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="34px">$30</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
                        </tr>
                     </table>
                  </div>
                  <div class="item-holder">
                     <table align="center" width="256px" cellpadding="0px" cellspacing="0px">
                        <tr>
                           <td class="item-info" align="center" height="34px">Item name</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="230px">
                              <img src="<?php echo base_url();?>Public/img/3-flowers.png" width="256" height="230" />
                           </td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="34px">$30</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
                        </tr>
                     </table>
                  </div>
                  <div class="item-holder">
                     <table align="center" width="256px" cellpadding="0px" cellspacing="0px">
                        <tr>
                           <td class="item-info" align="center" height="34px">Item name</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="230px">
                              <img src="<?php echo base_url();?>Public/img/sunflowers.png" width="256" height="230" />
                           </td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="34px">$30</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
                        </tr>
                     </table>
                  </div>
                  <div class="item-holder">
                     <table align="center" width="256px" cellpadding="0px" cellspacing="0px">
                        <tr>
                           <td class="item-info" align="center" height="34px">Item name</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="230px">
                              <img src="<?php echo base_url();?>Public/img/treecard.png" width="256" height="230" />
                           </td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="34px">$30</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
                        </tr>
                     </table>
                  </div>
                  <div class="item-holder">
                     <table align="center" width="256px" cellpadding="0px" cellspacing="0px">
                        <tr>
                           <td class="item-info" align="center" height="34px">Item name</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="230px">
                              <img src="<?php echo base_url();?>Public/img/3-flowers.png" width="256" height="230" />
                           </td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="34px">$30</td>
                        </tr>
                        <tr>
                           <td class="item-info" align="center" height="35px"><input name="btn_read" class="readbtn" value="Read More" /></td>
                        </tr>
                     </table>
                  </div>
               </div>
            </div>
         </div>
         <div style="clear:both"></div>
         <div class="level4">
            <div class="footer-area">
               <div class="lined-space"></div>
               <div class="site-map" align="left">
                  <table>
                     <tr>
                        <td class="footer-text"><a href="#">About Us</a></td>
                        <td class="footer-text"><a href="#">Facebook</a></td>
                     </tr>
                     <tr>
                        <td class="footer-text"><a href="#">Contact Us</a></td>
                        <td class="footer-text"><a href="#">Twitter</a></td>
                     </tr>
                     <tr>
                        <td class="footer-text"><a href="#">FAQs</a></td>
                        <td class="footer-text"><a href="#">Terms & Conditions</a></td>
                     </tr>
                     <tr>
                        <td class="footer-text"><a href="#">Help</a></td>
                     </tr>
                  </table>
               </div>
               <div class="developer-info">
                  <a class="developers-text">Designed & Developed By Diluks Software Solutions.</a>
               </div>
            </div>
         </div>
      </div>
      </form>
   </body>
</html>

And the controller for that (welcome_controller) is the following,

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome_controller extends CI_Controller {

function __construct(){
        parent::__construct();


    }

    public function index()
    {
        if(isset($_POST["btn_login"])){
          $data = array();
            $this->load->model('category_model');
            $data['categories'] = $this->category_model->getCategories();

          $this->load->view('login_view', $data);
        }
        else if(isset($_POST["btn_adminpanel"])){

          $this->load->view('adminpanel_view');
        }
        else if(isset($_POST["btn_logout"])){

          $this->session->sess_destroy();
          $data = array();
            $this->load->model('category_model');
            $data['categories'] = $this->category_model->getCategories();
            $this->load->view('home_view', $data);
        }
        else if(isset($_POST["btn_read"])){

            $this->load->view('readmore_view');

        }

    }


}

Now I need to redirect the page to readmore_view onClick of the button named 'btn_read', But it doesn't respond. (Note : There are 9 buttons with the same name, and I have tested changing one of them and give the particular name in controller, it didn't work either.) Please suggest me a solution.

Upvotes: 0

Views: 105

Answers (1)

Kumar V
Kumar V

Reputation: 8830

<input name="btn_read" class="readbtn" value="Read More" /> There is no input type. You have to mention the type of input.

<input type="submit" name="btn_read" class="readbtn" value="Read More" />

Upvotes: 2

Related Questions