Welcome Guest, Not a member yet? Register   Sign In
I must hack Validation library
#1

[eluser]Lima[/eluser]
Sorry I must hack Validation Library (system/libraries/Validation.php)

In the end of method run we'll see
Code:
foreach ($this->_error_array as $val)
{
  $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix."\n";
}
return FALSE;

In my case, I use property error_string on JavaScript. It show error on JavaScript because "\n".

example :
Code:
window.alert("The User field is required.
The Password field is required.");

so I must hack this library like this (without "\n") because nothing else I can do

Code:
foreach ($this->_error_array as $val)
{
  $this->error_string .= $this->_error_prefix.$val.$this->_error_suffix;
}
return FALSE;

if we need "\n" use set_error_delimiters

Do I do the right thing? I need another opinions.
Thanks.
#2

[eluser]wiredesignz[/eluser]
Create a MY_Validation extension in application/libraries, add your overrides by copying and modifying the original Validation functions.

Refer to the User Guide or search the forums on "Core Extensions".

This forum is for CI code contributions not for problem solving. Post your problems in Code & Application Development.
#3

[eluser]barbazul[/eluser]
Even easier: replace php breaklines ("\n") and make them look like javascript encoded breaklines ("\\n")... that way javascript wont complaint and will even respect your breaklines Big Grin

Code:
window.alert("<?=str_replace("\n","\\n",$this->validation->error_string); ?>");
#4

[eluser]Lima[/eluser]
OK, thank for your opinions. I think both of you right.




Theme © iAndrew 2016 - Forum software by © MyBB