• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with 'required' form validation.

hi. using code igniter 2.1.2
i have found a bug in the way code igniter renders the validation feedback for the required type.
i was getting a validation message of "The Address 1 field is The %s field is required.."
so i have looked into it. the file:
has the entry:
$lang['required'] = "The %s field is required.";
what i think is happening is when the /system/libraries/Form_validation.php _execute runs it must be somehow substituting the 'required' parameter with its key value.
i can't work out where this is happening, but simply changing the word 'required' to 'Required' in language entry 'The %s field is required' fixes the problem.

its got something to do with line 525 of form_validation.php
$message = sprintf($line, $this->_translate_fieldname($row['label']));
where $line = "The %s field is required"
$this->_translate_fieldname($row['label']) = 'Address 1'

its as if it is being called twice and 'required' is being translated to its language entry.
anyway, its late and i can't work it out. so hopefully someone else can work it out.

This is either a bug in only a very specific environment, or not a bug and your code is causing the issue. Maybe you should post your code to see.

I'm not sure I understand your problem 100% but I guess it is your code causing trouble since I never experienced any similar problems - and believe me, I really know how CI like the back of my hand Wink
So please, post your trouble causing code (if it's too many lines use gist)

yeah, it was late i worked it out. i have a dual language website, and before i render the html i do a substitute through all the elements of the $lang[] array. i didn't realise that code igniter had its own system elements in this array.
so, i have a helper:

function lang_sub($str,$obj,$params = '')
// substitutes language of a string.
switch ($obj->session->userdata('usr_language'))
  case 'am':
   $obj->lang->load('site', 'am');
  case 'en':
   $obj->lang->load('site', 'english');
foreach ( $obj->lang->language as $key=>$value)
  $str = str_replace($key, $value, $str);
if (is_array($params))
  $str = vsprintf($str,$params);
return $str;  

and that was causing the problem.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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