rachidE Junior Member
Posts: 12
Threads: 1
Joined: May 2018
Reputation:
0
hello,
I've been trying for a few hours to implement the validation form, but at runtime nothing happens.
this is my form :
Code:
<?php include_once 'header.php';?>
<div class="container">
<div class="card card-container">
<!-- <img class="profile-img-card" src="//lh3.googleusercontent.com/-6V8xOA6M7BA/AAAAAAAAAAI/AAAAAAAAAAA/rzlHcD0KYwo/photo.jpg?sz=120" alt="" /> -->
<img id="profile-img" class="profile-img-card" src="//ssl.gstatic.com/accounts/ui/avatar_2x.png" />
<p id="profile-name" class="profile-name-card"></p>
<form name="Login_form" class="form-signin" method="post" action="<?php echo base_url('login_controller/login_pro');?>" >
<input type="text" name="Username" class="form-control" placeholder="Username" >
<input type="password" name="Password" class="form-control" placeholder="Password" >
<div id="remember" class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block btn-signin" type="submit">Sign in</button>
</form><!-- /form -->
<a href="#" class="forgot-password">
Forgot the password?
</a>
</div><!-- /card-container -->
</div><!-- /container -->
<?php include_once 'footer.php';?>
and this is my controller :
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login_controller extends CI_Controller {
public function index()
{
echo 'welcome to login';
}
function login_pro()
{
/*echo $user = $this->input->post('user');
echo $pass = $this->input->post('pass');*/
$this->form_validation->set_rules('Username','Username','required');
$this->form_validation->set_rules('Password','Password','required');
}
}
I had activated the url and form helper, and also the form_validation library in the autoload file.
thank you in advance.
jreklund Administrator
Posts: 1,408
Threads: 3
Joined: Aug 2017
Reputation:
43
rachidE Junior Member
Posts: 12
Threads: 1
Joined: May 2018
Reputation:
0
(05-04-2018, 12:37 PM) jreklund Wrote: You have forgotten to include the RUN function*. You should have a go with this tutorial first:
https://www.codeigniter.com/user_guide/l...n-tutorial
* $this->form_validation->run()
I introduced the function RUN (), but it did not change anything :
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login_controller extends CI_Controller {
public function index()
{
echo 'welcome to login';
}
function login_pro()
{
/*echo $user = $this->input->post('user');
echo $pass = $this->input->post('pass');*/
$this->form_validation->run();
$this->form_validation->set_rules('Username','Username','required');
$this->form_validation->set_rules('Password','Password','required');
if ($this->form_validation->run() == FALSE)
{
echo 'try again';
}
else
{
echo 'welcome';
}
}
}
rachidE Junior Member
Posts: 12
Threads: 1
Joined: May 2018
Reputation:
0
(05-05-2018, 02:24 AM) jreklund Wrote: You need to read the tutorial again, now you got two RUN() functions.
Start fresh and just copy that code before you try to introduce your code.
same, I introduced a single function, but it still does not block when the fields are empty
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login_controller extends CI_Controller {
public function index()
{
echo 'welcome to login';
}
function login_pro()
{
/*echo $user = $this->input->post('user');
echo $pass = $this->input->post('pass');*/
$this->form_validation->set_rules('Username','Username','required');
$this->form_validation->set_rules('Password','Password','required');
if ($this->form_validation->run() == FALSE)
{
echo 'try again';
}
else
{
echo 'welcome';
}
}
}
rachidE Junior Member
Posts: 12
Threads: 1
Joined: May 2018
Reputation:
0
(05-05-2018, 08:13 AM) jreklund Wrote: Here's the tutorial, try it with a fresh copy of Codeigniter. (It works)
You can tell CI to log everything it's doing by changing:
/application/config/config.php
$config['log_threshold'] = 4;
Logs are in:
/application/logs/
hello,
your solution works, but not my form.
I rerun my form with logging enabled. and that generated me the log file as an attachment.
Attached Files
log-2018-05-08.php (Size: 8.4 KB / Downloads: 62)
qury Member
Posts: 86
Threads: 5
Joined: Feb 2015
Reputation:
4
Hi in the controller you need to ensure that the library and necessary helpers are loaded:
PHP Code:
public function login_pro () { /*echo $user = $this->input->post('user'); echo $pass = $this->input->post('pass');*/ // Loading helpers and library $this -> load -> helper (array( 'form' , 'url' )); $this -> load -> library ( 'form_validation' ); $this -> form_validation -> set_rules ( 'Username' , 'Username' , 'required' ); $this -> form_validation -> set_rules ( 'Password' , 'Password' , 'required' ); if ( $this -> form_validation -> run () == FALSE ) { echo 'try again' ; } else { echo 'welcome' ; } }
qury Member
Posts: 86
Threads: 5
Joined: Feb 2015
Reputation:
4
(05-08-2018, 06:03 AM) rachidE Wrote: I've already done that, but without success
OK!
I've taken the code you have pasted in and created a brand new installation of CI 3.1.8
In order to get this thing working i had to do 2 changes to your code:
1, in the form i've changed base_url() to site_url()
2, see the example class
PHP Code:
<?php class Test extends CI_Controller { public function __construct () { parent :: __construct (); // Loading helpers and library $this -> load -> helper (array( 'form' , 'url' )); $this -> load -> library ( 'form_validation' ); } function login_pro () { $this -> form_validation -> set_rules ( 'Username' , 'Username' , 'required' ); $this -> form_validation -> set_rules ( 'Password' , 'Password' , 'required' ); if ( $this -> form_validation -> run () == FALSE ) { echo 'try again' ; } else { echo 'welcome' ; } } }
Now, this is working fine on linux on PHP 7.2.5
Personally i do not like the case sensitive name tags in the form, so if it would be up to me u would rename Username to username, but that is just my preference..