Welcome Guest, Not a member yet? Register   Sign In
Validation bug - cant esplain just read
#1

[eluser]Phil Sturgeon[/eluser]
Hey, not entirely sure whats going on here. Its the first time I have properly used the validation class on a form that has database entries in it to begin with, and im not having alot of fun.

You can see I have defined 5 fields names, they are the only ones with ruels and therefore I imagine the only ones that need to be named. It seems that when I add information, it will save it fine but the variables for those 5 named in $fields will not be loaded. They are in db, just dont show.

When I comment out set_fields() they show fine.

Code:
$rules = array(
'user_firstname'  => 'trim|required',
'user_lastname'  => 'trim|required',
'personal_url'  => 'trim|max_length[100]',
'birthday'   => 'trim',
'location'   => 'trim',
'occupation'  => 'trim|xss_clean',
'interests'   => 'trim|xss_clean',
'aol_im'   => 'trim',
'icq_number'  => 'trim',
'yahoo_im'   => 'trim',
'msn_im'   => 'trim|valid_email',
'gtalk_im'   => 'trim|valid_email',
'about_me'   => 'trim'
);

$fields = array(
'user_firstname' => $this->lang->line('first_name'),
'user_lastname'  => $this->lang->line('last_name'),
'personal_url'  => $this->lang->line('personal_url'),
'msn_im'   => $this->lang->line('msn_im'),
'gtalk_im'   => $this->lang->line('gtalk_im')
);

$this->validation->set_rules($rules);
$this->validation->set_fields($fields);

if ($this->validation->run() === FALSE):
  
   // Just using the rules array to get a list of field names
   foreach(array_keys($rules) as $field):
$this->data[$field] = (isset($this->validation->$field)) ? $this->validation->$field : $this->user_model->getPropFromID($field);
   endforeach;

blablabla...

So this brings me to my question, WTF?

I am a noob with the validation class so feel free to laugh untill I bleed if its something silly.
#2

[eluser]Bulk[/eluser]
You need $field lines for each of the rules, even if you just leave it blank - the validation class uses both arrays to populate the form.
#3

[eluser]Phil Sturgeon[/eluser]
Doesnt much explain the backwards nature of my bug though surely? What sort of silly library wipes data from the only ones entered into the array, I would have thought the ones without field would have failed...

Time for validation lib modifications methinks.
#4

[eluser]Phil Sturgeon[/eluser]
Edit, no ignore that, that code was stupid. I will just be a good boy and define all $field's. Sad
#5

[eluser]esra[/eluser]
There was a mythological creature...a bird called the Phoenix that would ignite at death and then ressurect itself. I believe that the first version of PNphpBB was released for a version of Postnuke called Phoenix. All this sort of goes with your handle.

Anyhow.. have you seen these two gems:

http://ellislab.com/forums/viewthread/51260/

later followed by:

http://ellislab.com/forums/viewthread/53504/




Theme © iAndrew 2016 - Forum software by © MyBB