We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Codeigniter Form not working

Development and Programming

rdarby's avatar
rdarby
1 posts
11 years ago
rdarby's avatar rdarby

I am trying to create a search form in my codeigniter site header, however everytime the form is submitted, I receive a 404 error saying the page cannot be found! I have attempted to create a link to a test page and this gave me the same error.

Please observe my code below.

view(site_header)

<?php echo doctype(); ?> <html lang=”en”> <link href=”<?php echo base_url(); ?>styles/style.css” type=”text/css” rel=”stylesheet”/> <head>

    <title>/title>
    <div id="container">
        <div id="search">
            <?php

             echo form_open('search_keyword');
             echo form_label("Stumble a search ", "searchfor");
             echo form_input("search","search");
             echo form_submit("getSearch","Search");
             echo form_close(); ?>
        </div>

    </div>
</head>

</html> model (model_search)

<?php class Model_search extends CI_Model {

public function get_results($search_term){
   $query = $this->db->query('SELECT embed, title FROM videos WHERE tags LIKE '%$search_term%' order by RAND() LIMIT  1');
  return $query->result();

}

} ?> Controller (site.php) default controller

<?php

if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Site extends CI_Controller { public function index(){ $this->home(); }

public function home(){ 
    $this->load->model("model_get");
    $data["results"] = $this->model_get->getRand();
    $this->load->view("site_header");
    $this->load->view("site_content", $data);
    $this->load->view("site_footer");
}      
public function search_keyword()
{
    $this->load->model('model_search');
    $search_term  =  $this->input->post('search');
    $data['results'] = $this->model_search->get_results($search_term);
    $this->load->view('site_header');
    $this->load->view('search_content',$data);
    $this->load->view('site_footer');
}

}

?> Results page (search_content)

<body> <link href=”<?php echo base_url(); ?>styles/style.css” type=”text/css” rel=”stylesheet”/> <div id=”container”> <div id=”intro”> <?php echo heading(“Search Results”,1);?>
</div> <div id =”content”> Stumble videos related to <?php echo $search_term; ?> <?php foreach ($results as $row) { $title = $row->title; $vid = $row->embed; } echo heading($title, 3); echo $vid; ?>

    </div>
</div>

</body> perhaps I am missing something obvious, however I think it may be to do with my .htaccess file which is posted below

(.htaccess)

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /code/

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.