Beginner gets some problem - El Forum - 10-09-2010
[eluser]Achmed1[/eluser]
hi
This is my first post
Im new to codeigniter im having some problems i want to make a simpel login and a validate system example when i put a 4 charater then i get a message like your email must heave more than 4 this is my code.
login.php
Code: <html>
<head>
<title>Login</title>
<style type="text/css">
body {
background-color: #fff;
margin: 40px;
font-family: Lucida Grande, Verdana, Sans-serif;
font-size: 14px;
color: #4F5155;
}
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}
h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 16px;
font-weight: bold;
margin: 24px 0 2px 0;
padding: 5px 0 6px 0;
}
code {
font-family: Monaco, Verdana, Sans-serif;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}
</style>
</head>
<body>
<?php echo validation_errors(); ?>
<?php echo form_open('inloggen/logg'); ?>
<h1>Welcome log in </h1>
Name : <input type="text" name="gebruiker" />
Password : <input type="password" name="password"/>
<input type="submit" value="submit" />
</form>
</body>
</html>
inloggen.php
Code: <?php
class inloggen extends Controller {
function inloggen()
{
parent::Controller();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
}
function index()
{
$this->load->view('login');
}
function post()
{
$this->input->post('gebruiker');
$this->input->post('password');
}
function valideer()
{
$config = array(
array(
'field' => 'gebruiker',
'label' => 'Gebruiker',
'rules' => 'required'|'min_length[5]|max_length[12]'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'required'
)
);
$this->form_validation->set_rules($config);
$this->form_validation->run();
}
function logg()
{
}
}
/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */
Beginner gets some problem - El Forum - 10-09-2010
[eluser]mi6crazyheart[/eluser]
Why u want to force user for a specif type(min. 4 char) of email-id. Bcz, email-id is it self a unique address.
Any way, if u want to restrict user for 4 character email id then i think this validation rule will help u...
Code: $this->form_validation->set_rules('username', 'Username', 'required|min_length[4]');
For more info: http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html
Beginner gets some problem - El Forum - 10-10-2010
[eluser]Achmed1[/eluser]
Its not working
Beginner gets some problem - El Forum - 10-10-2010
[eluser]mikeymayhem[/eluser]
Think you should have a good read of the user guide about form validation but heres a step in the right direction. hope it helps you along the way
Controller
Code: <?php
class Inloggen extends Controller {
//note your class names shoudl start with an uppcase CHAR ie In
function Inloggen() {
parent::Controller();
//maybe think about autoloading these helpers
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
}
function index() {
$this->load->view('login');
}
function post() {
//not sure what your intention is here
$this->input->post('gebruiker');
$this->input->post('password');
}
function valideer() {
//you can save your validation rules one of two ways,
//as a config file called form_validation (see user guide)
//or by setting them individually in your controller. like so....
//the names specified in the rules should relate to the name fields of your
// form inputs
$this->form_valdiation->set_rules('username', 'Username', 'required|max_length[12]|min_length[5]');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE) {
//if the form validation returns false, ie has errors reload the view
//so we can display the errors
$this->load->view('login');
} else {
//validate user login details against the db or something here
}
}
}
Beginner gets some problem - El Forum - 10-10-2010
[eluser]Achmed1[/eluser]
This helped my thank you my problem was that i dont heave used the else $this->load->view('login'); to show the errors on the screen thank you very much
|