validation problem

#1
[eluser]-spy-[/eluser]
i was testing this code
Code:
<html>
<head>
<title>My Form</title>
</head>
<body>

<?=$this->validation->error_string; ?>

<?=form_open('form'); ?>

<h5>Username</h5>
&lt;input type="text" name="username" value="&lt;?=$this-&gt;validation->username;?&gt;" size="50" />

<h5>Password</h5>
&lt;input type="password" name="password" value="" size="50" /&gt;

<h5>Password Confirm</h5>
&lt;input type="password" name="passconf" value="" size="50" /&gt;

<h5>Email Address</h5>
&lt;input type="text" name="email" value="" size="50" /&gt;

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

&lt;/form&gt;

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

but error occured
Code:
Username
A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Validation::$username

Filename: views/myform.php

Line Number: 12
" size="50" />

what supposed to be the problem?

#2
[eluser]Sawariya[/eluser]
Check in your validation function ...


$field['username'] = "Username";

#3
[eluser]xwero[/eluser]
The validation values are only automatically set after the validation of the form field. If you want to add default values you have to make a loop where you add the values, for instance
Code:
$fields('username'=>'me');
foreach($fields as $key=>$val)
{
  $this->validation->$key = $val;
}

#4
[eluser]Sawariya[/eluser]
That ok...
here ur property name is not matching with ur validating field name

#5
[eluser]Peter Ivanov[/eluser]
Hello is there a way that i can use the validation class to validate variables,

is something like this possible

Code:
$var = 'is_this_email';

$test = $this->validation->...something($var);

if($test == true){
//bla bla
} else {
// something
}

#6
[eluser]tonanbarbarian[/eluser]
yes you could do something like that
Most of the rules that you can set such as required, matches, min_length, max_length, exact_length, valid_email, valid_ip, alpha, aplha_numeric, alpha_dash and numeric are just methods of the validation class that return a boolean value

so if you wanted to test if an email address was valid for example you could
Code:
if ($this->validation->valid_email('[email protected]'))...

#7
[eluser]Peter Ivanov[/eluser]
thanks tonanbarbarian,

this is pretty usefull

#8
[eluser]Chris Newton[/eluser]
You could also set the validation rules to check a callback function before the form will validate. Of course, this assumes you're pulling data from a form, and not just using the validation class by itself.

$rules['var'] = "required|min_length[5]|callback_variable_check";

Refer to the 'setting validation rules' of the documentation;
http://ellislab.com/codeigniter/user-gui...ation.html


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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