CI Validation value-data

#1
[eluser]Matthew90[/eluser]
Hey,

I use the validation class for a form.
Like in the example I use in the controller:

Code:
$rules['laufzeit'] = "exact_length[2]";
$rules['geldbetrag'] = "required|callback_betrag_check";
$rules['wagen'] = "required";
$rules['email']        = "required";


        
$this->validation->set_rules($rules);
        
if ($this->validation->run() == FALSE)
{
    $this->layout->buildPage("versicherungsrechner/uebersicht", $data);
}
else
{
    $this->layout->buildPage("versicherungsrechner/uebersicht", $data);
}

and for the view I use:
Code:
<?=form_open("versicherungsrechner_ergebnisse")?>
//some code
//line 25 follows...
<input type="text" name="email" value="<?=$this->validation->email;?>" size="50" />
</form>

And the result of this is:
Quote:A PHP Error was encountered
Severity: Notice

Message: Undefined property: CI_Validation::$email

Filename: versicherungsrechner/uebersicht.php

Line Number: 25

I have no more idea how to fix it...in fact it´s like in the example.
Does someone have an idea??

greetings

Matthias

#2
[eluser]webthink[/eluser]
just a guess but $this->validation->email probably requires you to have set_fields() so

...
...
$fields['email'] = "Email";
$this->validation->set_fields($fields);

#3
[eluser]Matthew90[/eluser]
thx for your suggestion, but unfortunately that doesn´t work...the same error msg...

#4
[eluser]webthink[/eluser]
Is there ever a point in your logic where you display the view without having called set_fields() in your controller? like when you initially visit the page or something like that.

#5
[eluser]Matthew90[/eluser]
I´m not sure if I understand you right.
I never use set_fields() in my controller before (it´s also the first time I use the validation-class)or what did you mean?

#6
[eluser]webthink[/eluser]
OK I believe in order to access $this->validation->my_field you must first have called set_fields with an array containing 'my_field'
What I meant is make sure you're logic is structured in such a way that you every time you call you're view you've already called set_fields.

#7
[eluser]Matthew90[/eluser]
ok, now I understand Wink
I use set_fields before display the datas, but input-text doesn´t work.
I also have a dropdown and radiobuttons and there is no problem to use it(also without set_fields), for example:

<?= $this->validation->set_select('laufzeit', '12'); ?> or <?= $this->validation->set_radio('wagen', 'gebraucht'); ?>

#8
[eluser]webthink[/eluser]
$this->validation->set_select(); and $this->validation->set_radio(); are functions (actually they're class methods) presumably defined in the class whereas $this->validation->my_field is a class attribute defined by you (by calling set_fields).

#9
[eluser]Matthew90[/eluser]
yes you´re right.
I also set the select-names in set_fields, what was wrong.

Now I change some code and now it´s working. It´s like you said, I have to use set_fields otherwise I will get an error (but it´s curious, because I use it after your first post...)
Well, it doesn´t matter anymore, big thanks to you :-)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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