Welcome Guest, Not a member yet? Register   Sign In
validation problem

i was testing this code
<title>My Form</title>

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

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

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

&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>



but error occured
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?

Check in your validation function ...

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

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
foreach($fields as $key=>$val)
  $this->validation->$key = $val;

That ok...
here ur property name is not matching with ur validating field name

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

is something like this possible

$var = 'is_this_email';

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

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

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
if ($this->validation->valid_email('[email protected]'))...

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

this is pretty usefull

[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;

Theme © iAndrew 2016 - Forum software by © MyBB