• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
validation dont't show message

#1
[eluser]kiyo[/eluser]
hello, I'm a newbie phpframework.
Today I test form_validate but it don't show error
or something

edit: remove unuse code

#2
[eluser]jdfwarrior[/eluser]
Why are you doing this?

Code:
<?php echo var_dump(validation_errors()); ?>

This will work:
Code:
<?=validation_errors();?>

Also, I'm assuming your auto loading the form validator? You don't have a load command there for it.

#3
[eluser]kiyo[/eluser]
Thank lab assistant
but it not work

I load form validate at constructor

here this code
Code:
class Register Extends Controller{
        function register(){
            parent::Controller();
            $this->load->helper("form");
            $this->load->library("form_validation");
            
        }

#4
[eluser]jdfwarrior[/eluser]
That's not how you call the constructor. Check the user guide on controllers. There is a section about the constructor.

#5
[eluser]jdfwarrior[/eluser]
Ok now that I'm back on a computer and not trying to reply from my phone..

The constructor is created by creating a _construct function.

Code:
class Register extends Controller {

    function _construct() {

        $this->load->library('form_validation');
        $this->load->helper('form');

    }

}

Making a register function doesn't mean its the constructor. To CI, its just another function. Would be accessed by navigating to: www.example.com/register/register

EDIT: Nm, your code is right as well, depending on which version of PHP your using. PHP5+ uses the method I showed.

via: User Guide - Controllers

#6
[eluser]kiyo[/eluser]
thank you very much
I write code from guideline

new screenshot << validate error don't show mesage

I change a little in controller/register.php
Code:
class Register Extends Controller{
        function _construct() { // for php5

        $this->load->library('form_validation');
        $this->load->helper('form');

    }
        
        function index(){
            $data["head"] = "register new user";
            $data["title"] = "form register new user";
            $data["meta"] = "register form ";
            $this->load->view("register_view",$data);
        }
        
        function register_process(){
           $data["head"] = "register new user";
            $data["title"] = "form register error";
            $data["meta"] = "register form ";
            $this->form_validation->set_rules("username","username","required|min_length[5]");
            

            
            if($this->form_validation->run() == false){
                
                $this->load->view("register_view",$data);
            }else{
                
                echo "complete";
            }
        }
}

and this is a view/register_process.php
Code:
&lt;?php echo var_dump(validation_errors()); ?&gt; //try to dump data but it empty ,why?

&lt;?=form_open("register/register_process")?&gt;

<table width="360" border="0" cellspacing="0" cellpadding="1">
  <tr>
    <td width="179"><div align="right">username</div></td>
    <td width="177">&lt;input name="username" type="text" id="username" value ="&lt;?=set_value("username","1")?&gt;"/&gt;&lt;/td>
  </tr>

  <tr>
    <td>&lt;input type="submit" name="Submit" value="Submit" /&gt;&lt;/td>
    <td>&nbsp;</td>
  </tr>
</table>
&lt;?=form_close()?&gt;

#7
[eluser]jdfwarrior[/eluser]
Did you try changing the register function to being a constructor by PHP5 standards? Change the register function to be:

Code:
class Register Extends Controller{
        function _construct(){ //instead of function register() {
            parent::Controller();
            $this->load->helper("form");
            $this->load->library("form_validation");
            
        }
        
        function index(){
            $data["head"] = "register new user";
            $data["title"] = "form register new user";
            $data["meta"] = "register form ";
            $this->load->view("register_view",$data);
        }
        
        function register_process(){
           $data["head"] = "register new user";
            $data["title"] = "form register error";
            $data["meta"] = "register form ";
            $this->form_validation->set_rules("username","username","required|min_length[5]");
            

            
            if($this->form_validation->run() == false){
                
                $this->load->view("register_view",$data);
            }else{
                
                echo "complete";
            }
        }
}

#8
[eluser]kiyo[/eluser]
sorry , that my fault
after I chage constructor
It show "Fatal error: Call to undefined function validation_errors() "

I think we already load library

>>> Test online here <<<<

#9
[eluser]Dam1an[/eluser]
The constructor should start with a double underscore
Code:
function __construct()...

#10
[eluser]kiyo[/eluser]
[quote author="Dam1an" date="1243601896"]The constructor should start with a double underscore
Code:
function __construct()...
[/quote]


I change to function __construct() already
but still don't show message.

may be I mistake config or error report?

at Test online program
work with right way <test input more than 5 character>


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.