CodeIgniter Forums
Validation library usage for form validation. Need help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Validation library usage for form validation. Need help (/showthread.php?tid=34012)



Validation library usage for form validation. Need help - El Forum - 09-15-2010

[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


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>
&lt;?php echo $this->validation->username_error; ?&gt;
&lt;input type="text" name="username" value="&lt;?php echo $this-&gt;validation->username;?&gt;" size="50" />

<div>&lt;input type="submit" value="Submit" /&gt;&lt;/div>
<br /><br />

&lt;?php echo form_close()?&gt;

&lt;/body&gt;
&lt;/html&gt;



Validation library usage for form validation. Need help - El Forum - 09-15-2010

[eluser]Thorpe Obazee[/eluser]
Try using the new Form validation


Validation library usage for form validation. Need help - El Forum - 09-16-2010

[eluser]prashid[/eluser]
Thanks for the reply. Form_Validation library is working but I want to use Validation library thats why asking solution to my problem. Sad


Validation library usage for form validation. Need help - El Forum - 09-16-2010

[eluser]danmontgomery[/eluser]
Validation library is deprecated in 1.7.2 (removed in 2.0) and replaced with form_validation, so you're not going to get much help with it.


Validation library usage for form validation. Need help - El Forum - 09-16-2010

[eluser]prashid[/eluser]
Got it