-1

I have a register view and a register controller and a header. in the header there is a drop down menu.

Now when I click on the login button from the header nav drop down menu, it doesn't do anything it only refreshes the page and doesn't take me to the login or registration page. (this is true for all my other views and controllers.)

even when I navigate to the URL hardcoded like /register/login it gives me 404 PAGE NOT FOUND error

How can I load my views correctly in the controllers and then navigate to them from my views.

What am I doing wrong?

Here is my code:

Controller for the register. Register.php:

class Register extends CI_Controller {

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

        $this->load->library(array(
            'session',
            'email',
            'form_validation',
        ));
        $this->load->database();
        $this->load->helper(array(
            'url',
            'string',
        ));
        $this->load->model(array(
            'auth_model',
            'user_model',
            'price_ranges_model',
            'category_model',
            'quote_model',
        ));
    }

    public function index()
    {
        $this->load->view('footer', array(
            'page_title' => 'Register',
        ));
        $this->load->view('register', array(
            'price_ranges' => $this->price_ranges_model->get(),
            'categories' => $this->category_model->get(),
            'delivery_timings' => $this->user_model->_delivery_timings,
        ));
        $this->load->view('footer');
    }

public function login()
    {
        $this->form_validation->set_rules('c_username', 'Username', 'required');
        $this->form_validation->set_rules('c_password', 'Password', 'required');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('header', array(
                'page_title' => 'Register',
            ));
            $this->load->view('register', array(
                'price_ranges' => $this->price_ranges_model->get(),
                'categories' => $this->category_model->get(),
                'delivery_timings' => $this->user_model->_delivery_timings,
            ));
            $this->load->view('footer');
        }

the register.php view:

<div class="col_two_third col_last nobottommargin">


                <h3>Don't have an Account? Register Now.</h3>

                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Unde, vel odio non dicta provident sint ex autem mollitia dolorem illum repellat ipsum aliquid illo similique sapiente fugiat minus ratione.</p>

                <form class="nobottommargin" method="post" action="<?=site_url('register/post')?>">

                    <div class="col_half">
                        <label for="register-form-name">Customer Name:</label>
                        <input type="text" id="qname" name="name" value="<?=set_value('name')?>" class="form-control" />
                        <?php echo form_error('name'); ?>
                    </div>
                    
                

                    <div class="col_half">
                        <label for="register-form-email">Email Address (Username):</label>
                        <input type="email" id="qemail" name="email" value="<?=set_value('email')?>" class="form-control" />
                        <?php echo form_error('email'); ?>
                    </div>

                    <

                    <div class="col_half">
                        <label for="register-form-password">Password:</label>
                        <input type="password" id="qpassword" name="password" value="" class="form-control" />
                        <?php echo form_error('password'); ?>
                    </div>

                    <div class="col_half col_last">
                        <label for="register-form-cpassword">Confirm Password:</label>
                        <input type="password" id="qcpassword" name="password_confirm" value="" class="form-control" />
                        <?php echo form_error('password_confirm'); ?>
                    </div>

                        <?php echo form_error('est_amount'); ?>
                    </div>

the header.php view:

<div class="top-links on-click">
                            <form class="form-inline m-0" method="post" action="<?=base_url('register/login')?>">
                              <div class="form-group m-2">
                                <input type="email" class="form-control form-control-sm" placeholder="Username" name="c_username" required>
                              </div>
                              <div class="form-group m-2">
                                <input type="password" class="form-control form-control-sm" placeholder="Password" name="c_password" required>
                              </div>
                              <button type="submit" class="btn btn-sm btn-primary m-2">GO</button>
                            </form>
                        </div><!-- .top-links end -->
james
  • 29
  • 1
  • 6

1 Answers1

0

I think you should check your base URL.

The URL you navigate through have index.php in it ? Like

http://localhost.com/index.php/register/login

Or you have place the index.php already in application/config/config.php file, the baseurl as

$config['base_url'] = 'http://localhost.com/index.php';

Or you can also configure it in your .htaccess file like this.

Also for the views I recommend don't load them from the function again and again.

Try to load them in the view like

in register.php

<?php $this->load->view('header'); ?>

//html of register page
<div class="col_two_third col_last nobottommargin">
  …
</div>

<?php $this->load->view('footer'); ?>
Haris
  • 71
  • 3