Welcome Guest, Not a member yet? Register   Sign In
blank set_value() return default value
#8

(04-12-2015, 10:59 AM)silentium Wrote: After digging through the core of CI 2.2 and CI 3, there are one small difference in the code that seems to be creating this issue.

In CI 3, in system/libraries/Form_validation.php line 941 the set_value() method check if the field exists and have any postdata



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


The same code in CI 2.2 only check if the field exists, but not if it has any content. Line 732.



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


When form validation is executed with run(), it does not set the postdata for a field if it is empty. CI 3 system/libraries/Form_validation.php line 466



PHP Code:
elseif (isset($validation_array[$field]) && $validation_array[$field] !== '')
{
 
   $this->_field_data[$field]['postdata'] = $validation_array[$field];


This is the same in both CI 2.2 and CI 3. So due to that CI 3 check if the field has any data, which it don't have if submitted empty, it returns the default field value.

Sum up
Both CI 2.2 and CI 3 sets the postdata in the same way when using the form validation on form submission. But a change in CI 3, namely the adding of checking if a field have any postdata, returns the fields default value if that field was submitted empty.

This can be considered as an issue?
Reply


Messages In This Thread
RE: blank set_value() return default value - by Reirei - 04-13-2015, 03:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB