Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update system/libraries/Form_validation.php #947

Closed
wants to merge 3 commits into from

3 participants

@dionysiosarvanitis

Problems with repopulating fields if form_validation is loaded (Issue #104)

If you do not specifiy a rule in the form validation, set_value in form_helper.php returns empty or sets default value for that field, instead of the postdata.

system/libraries/Form_validation.php
((6 lines not shown))
{
- return $default;
+ if( $this->CI->input->post($field)===FALSE)

Could you please follow the style guide for spacing, tabs and if statements?

http://codeigniter.com/user_guide/general/styleguide.html

Thank you! :)

I'm trying !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
system/libraries/Form_validation.php
((6 lines not shown))
{
- return $default;
+ if ( $this->CI->input->post($field) === FALSE)

Sorry dude but it's if ($this....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
system/libraries/Form_validation.php
@@ -738,15 +745,23 @@ public function set_select($field = '', $value = '', $default = FALSE)
{
if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
{
- if ($default === TRUE AND count($this->_field_data) === 0)
- {
- return ' selected="selected"';
+ if( ! ($this->CI->input->post($field) === FALSE))
+ {
+ $field = $this->CI->input->post($field);
+ }
+ else
+ {

Also spacing here looks pretty whack.

I think it's ok now!
there were some spaces in front, causing the problem.

thanks for the advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@narfbg narfbg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 9 deletions.
  1. +24 −9 system/libraries/Form_validation.php
View
33 system/libraries/Form_validation.php
@@ -707,13 +707,20 @@ protected function _translate_fieldname($fieldname)
*/
public function set_value($field = '', $default = '')
{
- if ( ! isset($this->_field_data[$field]))
+ if ( ! isset($this->_field_data[$field]) OR $this->_field_data[$field]['postdata'] === NULL)
{
- return $default;
+ if ($this->CI->input->post($field) === FALSE)
+ {
+ return $default;
+ }
+ else
+ {
+ return $this->CI->input->post($field);
+ }
}
// If the data is an array output them one at a time.
- // E.g: form_input('name[]', set_value('name[]');
+ // E.g: form_input('name[]', set_value('name[]');
if (is_array($this->_field_data[$field]['postdata']))
{
return array_shift($this->_field_data[$field]['postdata']);
@@ -738,15 +745,23 @@ public function set_select($field = '', $value = '', $default = FALSE)
{
if ( ! isset($this->_field_data[$field]) OR ! isset($this->_field_data[$field]['postdata']))
{
- if ($default === TRUE AND count($this->_field_data) === 0)
+ if( ! ($this->CI->input->post($field) === FALSE))
{
- return ' selected="selected"';
+ $field = $this->CI->input->post($field);
+ }
+ else
+ {
+ if ($default === TRUE AND count($this->_field_data) === 0)
+ {
+ return ' selected="selected"';
+ }
+ return '';
}
- return '';
}
-
- $field = $this->_field_data[$field]['postdata'];
-
+ else {
+ $field = $this->_field_data[$field]['postdata'];
+ }
+
if (is_array($field))
{
if ( ! in_array($value, $field))
Something went wrong with that request. Please try again.