• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
blank set_value() return default value

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.

Messages In This Thread
RE: blank set_value() return default value - by silentium - 04-12-2015, 10:59 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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