0

I'm trying to execute a PHP class after a HTML form submit but my browser display that it couldn't open the specify address. Here's my form:

<!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' xml:lang='en' lang='en'>

<head>    
    <title>Logins</title>
</head>
<body>
    <div id='login_form'>
        <form action='<?php echo base_url();?>Login/process' method='post' name='process'>
            <h2>User Login</h2>
            <br />            
            <label for='username'>UsernameTest</label>
            <input type='text' name='username' id='username' size='25' /><br />

            <label for='password'>Password</label>
            <input type='password' name='password' id='password' size='25' /><br />                            

            <input type='Submit' value='Login' />            
        </form>
    </div>
</body>
</html>

And here's my PHP's class:

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

class Login extends CI_Controller{

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

    public function index(){
        // Load our view to be displayed
        // to the user
        $this->load->view('login_view');
    }

        public function process(){
        // Load the model
        $this->load->model('login_model');
        // Validate the user can login
        $result = $this->login_model->validate();
        // Now we verify the result
        if(! $result){
            // If user did not validate, then show them login page again
            $this->index();
        }else{
            // If user did validate, 
            // Send them to members area
            redirect('home');
        }        
    }
}
?>

The class is in the Controller folder and the form is in the View folder

Thank's

Naruto
  • 1,210
  • 3
  • 25
  • 28
S7_0
  • 1,165
  • 3
  • 19
  • 32
  • 1
    Well, obviously, yes. He is using CodeIgniter. Do you have any routes that may overwrite the default route (class/method) ? – mariobgr Sep 01 '15 at 09:46
  • I think you need to use `site_url()` instead of base. – Sam Teng Wong Sep 01 '15 at 09:49
  • Hello everybody, I'm currently using Codeigniter and honestly copy/past a code found on internet. But what do you mean about "any routes " that could overwrite the (class/method) ? Thank's – S7_0 Sep 01 '15 at 09:49

3 Answers3

1

If you configured your site as something like http://www.mywebsite.org in your config file, then the line:

<form action='<?php echo base_url();?>Login/process' method='post' name='process'>

Will render as:

<form action='http://www.mywebsite.orgLogin/process' method='post' name='process'>

which is obviously not what you intended because http://www.mywebsite.orgLogin/process isn't even a valid URL. To render URLs in CodeIgniter, use site_url():

<form action='<?php echo site_url('Login/process');?>' method='post' name='process'>

Aside for this, there may be two other problems you might want to check out:

  • the /Login/process page doesn't exist
  • the /home page doesn't exist
Lucian D.
  • 95
  • 5
0

First echo or dump your base_url() to see what is there, or use site_url() .I usually use '/' as /controller_name/function and please use 'login' not 'Login'.

Saty
  • 22,443
  • 7
  • 33
  • 51
Răducanu Ionuţ
  • 430
  • 2
  • 11
  • I display the value of site_url() and gave me: __ localhost:8888/CodeIgniter-3.0.0/index.php/login/process __ Exactly what I want without the uppercase 'L' otherwise, it still doesn't work. But can you tell me why need I to write 'login' and not 'Login' (The both case doesn't work). – S7_0 Sep 01 '15 at 10:44
0

It works when I write manually the following URL:

localhost:8888/CodeIgniter-3.0.0/index.php/Login/process

But doesn't work using the form redirection.

<form action='<?php echo site_url('Login/process/');?>' method='post' name='process'>

Thanks

S7_0
  • 1,165
  • 3
  • 19
  • 32
  • Include url helper in your controller or in autoload file. – Tpojka Sep 01 '15 at 11:43
  • @I've tried to add --- $this->load->helper('url'); --- Nothing change – S7_0 Sep 01 '15 at 11:52
  • Show your `.htaccess` file. – Tpojka Sep 01 '15 at 11:54
  • @Tpojka Require all denied Deny from all – S7_0 Sep 01 '15 at 12:01
  • @Tpojka I'm not really sure about the report between my problem and the .htaccess. Do you think that the problem is about my URL ? Thanks – S7_0 Sep 01 '15 at 13:50
  • If you want to use URL without `index.php` you have to rewrite it with `.htaccess`. Regardless, you can also use apache flag to solve that matter. Check [here](http://stackoverflow.com/questions/16579652/htaccess-case-sensitive-and-mod-rewrite#answer-16579927). – Tpojka Sep 01 '15 at 13:58
  • For the moment, it doesn't disturb me if there's index.php into my URL. But is there a report between my problem and the URL ? thanks – S7_0 Sep 01 '15 at 14:10
  • Not sure but maybe something with machine/OS? – Tpojka Sep 01 '15 at 14:21
  • I'm using Os Maverick and MAMP – S7_0 Sep 01 '15 at 14:39