CodeIgniter Forums
problem with 'required' form validation. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: problem with 'required' form validation. (/showthread.php?tid=53826)



problem with 'required' form validation. - El Forum - 08-10-2012

[eluser]pgee70[/eluser]
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:
/system/language/english/form_validation_lang.php
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.







problem with 'required' form validation. - El Forum - 08-10-2012

[eluser]Aken[/eluser]
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.


problem with 'required' form validation. - El Forum - 08-10-2012

[eluser]PhilTem[/eluser]
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)


problem with 'required' form validation. - El Forum - 08-10-2012

[eluser]pgee70[/eluser]
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:

Code:
function lang_sub($str,$obj,$params = '')
{
// substitutes language of a string.
switch ($obj->session->userdata('usr_language'))
{
  case 'am':
   $obj->lang->load('site', 'am');
   break;
  case 'en':
  default:
   $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.