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

#1
Code:
set_value('user[name]', $user->name);

On use this code im my input, the input value is set to default ($user->name) when loaded.
By replacing the default value with a blank value and send the form, the input is displayed with the default value with the form error 'required'.

I want the value, even blank, is setted after sending the form.
I'm using codeigniter 3, if i remember, this did not occur in 2.

Thanks.
Reply

#2
(04-01-2015, 04:57 PM)Reirei Wrote:
Code:
set_value('user[name]', $user->name);

On use this code im my input, the input value is set to default ($user->name) when loaded.
By replacing the default value with a blank value and send the form, the input is displayed with the default value with the form error 'required'.

I want the value, even blank, is setted after sending the form.
I'm using codeigniter 3, if i remember, this did not occur in 2.

Thanks.

I'm having the same problem in v3.0.1-dev.
Reply

#3
I'm having the same problem in 3.0.1-dev.
Reply

#4
Help?!
Reply

#5
If the user submit the field empty, it's empty and if empty, the helper sets the default value.

Only way around would be to have a value in it.
Reply

#6
(04-10-2015, 10:05 AM)silentium Wrote: If the user submit the field empty, it's empty and if empty, the helper sets the default value.

Only way around would be to have a value in it.

I did a test in the ci 2.1 and works perfectly.

The correct is: If $_POST is empty, set values $default, else set values $_POST.
Reply

#7
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.
Reply

#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

#9
I would think so yes. At least I see it as a issue.

Report it on Github https://github.com/bcit-ci/CodeIgniter/issues to get a discussion about it to see what the developers of CI thinks.
Reply

#10
I setup a test page because the fix did not work for me.  I have discovered that if the "name" of the field is part of an indexed array, the problem will continue to occur.  I posted a MCVE and a live demo link at the GitHub thread...

https://github.com/bcit-ci/CodeIgniter/i...t-97716993
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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