Welcome Guest, Not a member yet? Register   Sign In
Form Validation - set_value() working differently in v3
#1

I'm using CodeIgniter v3 on a new project and noticed that Form Validation in conjunction with set_value() is not working the same as it did in CodeIgniter v2.

In CI version 3, set_value() is totally ignoring an empty string on a "required" validation error, where CI v2 did not.

The scenario is a form that can be used to "edit" existing data.  The page loads with the form fully populated with data.  Let's say every field is already set as "required".

Consider the following code...

Code:
<?php $first = isset($first) ? $first : ''; ?>
<input type="text" name="first" value="<?php echo set_value('first', $first); ?>" />

In CodeIgniter v2: if you blank out a few fields and hit submit, when the page reloads, you'll see validation errors, and the blanked out fields remain blank until you fix them.

In CodeIgniter v3: if you blank out a few fields and hit submit, when the page reloads, you'll see validation errors, but the blanked out fields reload with their original values; not blank as expected.
  • It's not a programming error... if you generate other kinds of validation errors, the page reloads and shows the newly entered data.
  • This data is not yet saved to the database.  It's just what is shown when the page reloads on validation errors.

So with the "required" rule on an empty field, set_value() simply ignores the empty string and reverts to the original value on a failed validation reload.  Under CI v2 it would load with the empty string (blank field) on a failed validation.

Is this new behavior an intentional or is this a bug?

The v3 documentation for set_value() is the same as v2

Thank-you!
Reply


Messages In This Thread
Form Validation - set_value() working differently in v3 - by sparky672 - 04-29-2015, 01:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB