09-15-2010, 09:25 PM
[eluser]prashid[/eluser]
I am using Validation library as autoload. Now problem is when I type in URL
http://localhost/CIB/test/ get error below and if browse http://localhost/CIB/test/check_user working fine.
I understand that default values are required if not calling check_user.
But I don't want to call check_user as default instead I want to call default index at start and once
user click button than check_user should be called. Am I right here?
So whats the solution here?. Should I use defaults in order call index at start? if yes whats the professional way to code
when there are many fields.
Thanks
I am using Validation library as autoload. Now problem is when I type in URL
http://localhost/CIB/test/ get error below and if browse http://localhost/CIB/test/check_user working fine.
I understand that default values are required if not calling check_user.
But I don't want to call check_user as default instead I want to call default index at start and once
user click button than check_user should be called. Am I right here?
So whats the solution here?. Should I use defaults in order call index at start? if yes whats the professional way to code
when there are many fields.
Thanks
Code:
//ERROR
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Validation::$username_error
Filename: views/test_view.php
Line Number: 11
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Validation::$username
Filename: views/test_view.php
Line Number: 12
//CONTROLLER called test.php
<?php
class Test extends Controller {
function index()
{
$this->load->view('test_view');
}
function check_user()
{
$this->_set_fields();
$this->_set_rules();
if ($this->validation->run() == FALSE)
{
$this->load->view('test_view');
}
else
{
$this->load->view('formsuccess');
}
}
function _set_fields()
{
$fields['username'] = 'Username';
$this->validation->set_fields($fields);
}
function _set_rules()
{
$rules['username'] = "required";
$this->validation->set_rules($rules);
$this->validation->set_message('required', '%s required');
}
}
//VIEW called test_view.php
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php echo $this->validation->error_string; ?>
<?php echo form_open('form/check_user'); ?>
<h5>Username</h5>
<?php echo $this->validation->username_error; ?>
<input type="text" name="username" value="<?php echo $this->validation->username;?>" size="50" />
<div><input type="submit" value="Submit" /></div>
<br /><br />
<?php echo form_close()?>
</body>
</html>