0

in the below code i am searching a data before searching my url will be in coursemaster_site and when i search it will be in coursemaster_site/index1 and when i close the search results the url will be in coursemaster_site /coursemaster_site but i want url to be in coursemaster_site after closing the search results.

controller:coursemaster_site

function index1()
    {
        $data            = array();
        $keyword         = $this->input->post('keyword');
        if($keyword!=""){
            $data['results'] = $this->coursemaster_model->search($keyword);
        }
        $this->load->view('coursemaster_view', $data);

    }

view:coursemaster_view

<form action="<?php echo site_url('coursemaster_site/index1');?>" method = "post">
<br/><center>SEARCH:<input type="text" name = "keyword" required/>
<input type="submit" name="submit" id="opn" value = "Search"  onClick="hide1('hiddendiv')"  class="btn-success btn" /></center>
</form>

<?php
if (isset($_POST['submit'])) { // Here
  // Do the search here
        if($results){
         ?> <div id='hideme'>
         CLOSE<a href='coursemaster_site' class='close_notification' title='Click to Close'>
        <img  src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close"    onClick="hide('hideme')"/>
        </a><div style="background:#FFFFFF; width:1000px; height: 540px; position: absolute; left: 20%; top: 35%; margin-left: -100px; margin-top: -120px" id="modal"  >
       <table class="display2 table table-bordered table-striped" id='results'>
       <tr>
            <th>course_code</th>
            <th>course name</th>
       </tr>
       <tr><?php
             foreach ($results as $row) {
      ?>
       <td><?php echo $row->course_code;?></td>
       <td><?php echo $row->course_name;?></td>
       </tr>
            <?php
            } 
        }else{
        echo"<div id='hideme'>
         CLOSE<a href='coursemaster_site' class='close_notification' title='Click to Close'>";
        echo "<div id='modal' style='background:#FFFFFF; width:1000px; height: 525px; position: absolute; left: 20%; top: 35%; margin-left: -100px; margin-top: -110px'>";
        }
  echo"no results";
  echo'</div>';
echo '</div>';        }
 // If closing
?>
</table>
</div></div>
<script>
$('a.modal').bind('click', function(event) { 
        event.preventDefault();
        $('#modal').fadeIn(10);

    });
    function hide(obj) {
        var el = document.getElementById(obj);
        el.style.display = 'none';
    }
    function hide1(obj) {
        var el = document.getElementById(obj);
        el.style.display = 'none';
    }
    </script>
plain jane
  • 1,009
  • 1
  • 8
  • 19
Moses
  • 35
  • 1
  • 6

2 Answers2

0

Do the following changes and check if it works or not:

<div id='hideme'>
     CLOSE<a href='javascript:void(0);' class='close_notification' title='Click to Close'>";
Nil'z
  • 7,487
  • 1
  • 18
  • 28
  • Putting `href='javascript:void(0);'` does not redirects. Put `href='javascript:void(0);'` to both the links and then check once. or just give this `href='=base_url('coursemaster_site')?>'` and check, this will redirect to the index function of the controller. – Nil'z Sep 17 '13 at 08:18
0

Change to:

<div id='hideme'>CLOSE
 <a href='/coursemaster_site' class='close_notification' title='Click to Close'> 
...

on both places. The leading slash makes the href start from root.

jtheman
  • 7,421
  • 3
  • 28
  • 39
  • i tried ur idea like this and got it /univproject/index.php/coursemaster_site – Moses Sep 17 '13 at 08:22
  • OK, great. I always remove the index.php/ part with .htaccess http://stackoverflow.com/questions/6765883/using-htaccess-to-remove-codeigniter-index-php-in-a-subdirectory – jtheman Sep 17 '13 at 08:24