CodeIgniter Forums
Possible bug in set_value method of Form Validation Library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Possible bug in set_value method of Form Validation Library (/thread-14819.html)



Possible bug in set_value method of Form Validation Library - El Forum - 01-16-2009

[eluser]everdaniel[/eluser]
Hi Guys!

I posted a comment about this in the forums yesterday and I think I found what's wrong with it a few hours ago, basically, my problem is:

I'm trying to re-populate a form with data from a db using the set_value() function, but this function only works when I enter the edit page for the first time (following a link), it doesn't work if I enter the edit page clicking on a submit button.

Reason is, if there is no data in the $_POST var, the fields that I define using set_rules() are not set, and the set_value() works. The set_value() only returns the default data if the field hasn't been set. Since I'm entering the page using a submit button, there is data in the $_POST var, the fields are set using the set_rules() and the form_validation returns the postdata he has for that field (which is empty, since I'm coming from another different page).

For better clarification, in line 732 in Form_validation.php file we have:

Code:
if ( ! isset($this->_field_data[$field]))
{
  return $default;
}

if the field is not set, the default data is returned, so if I change this to:

Code:
if ( ! isset($this->_field_data[$field]['postdata']))
{
  return $default;
}

then it works and the default data is set in the form fields.

Can anyone here confirm this? if it's a bug or it's just me? Tongue

Attached are files to test this.


Possible bug in set_value method of Form Validation Library - El Forum - 02-19-2009

[eluser]michaeljdennis[/eluser]
I've just come across this same problem. Ever find a solution?


Possible bug in set_value method of Form Validation Library - El Forum - 02-19-2009

[eluser]everdaniel[/eluser]
Sort of, what I did was that instead of using a button, I use a link to go back to the page where the form_validation ran, this way, I'm not sending anything in $_POST (if you use a button, you're sending data like the value of the button).

It is not a solution but it is what it works for me Big Grin


Possible bug in set_value method of Form Validation Library - El Forum - 02-20-2009

[eluser]michaeljdennis[/eluser]
Sounds good to me! Thanks for the quick reply!