CodeIgniter Forums
how to parse validation_errors(); - 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: how to parse validation_errors(); (/showthread.php?tid=20226)



how to parse validation_errors(); - El Forum - 07-02-2009

[eluser]nandish[/eluser]
Hi guys.

unterminated string problem.


In view page
[removed]
error = "<?php echo strip_tags(validation_errors()));?>";
alert(error);
[removed]

if it is single error it will alert the message,
but if its more than one error i had got error like unterminated string.

output
error = "passwrord filed is required.
verfication code is required.
first name is required. "


I removed \r\t\n character also but still no luck

Thanks in advance


how to parse validation_errors(); - El Forum - 07-02-2009

[eluser]TheFuzzy0ne[/eluser]
You can't be removing those non-printable characters, otherwise there would be no line breaks. Smile


how to parse validation_errors(); - El Forum - 07-02-2009

[eluser]srenon[/eluser]
You need to remove the newline characters before you assign it in JavaScript

$error = "passwrord filed is required......"; (on one line)

Code:
error = "<?php echo preg_replace("/(\n)+/m", ' ', strip_tags(validation_errors())));?>";

Quick Example
Code:
<?php
$error =  "passwrord filed is required.
              verfication code is required.
              first name is required.";
                        
              
        $error = preg_replace("/(\n)+/m", ' ', $error);
?>


[script language="javascript"]          
    document .write('<?= $error?>');
[/script]



how to parse validation_errors(); - El Forum - 07-02-2009

[eluser]srenon[/eluser]
Code:
error = "<?php echo preg_replace('/(\n)+/m', ' ', strip_tags(validation_errors())));?>";



how to parse validation_errors(); - El Forum - 07-02-2009

[eluser]srenon[/eluser]
Updated 'regular expression' (remove excess white space & list each error on a newline)
Code:
<?php
$error =  "passwrord filed is required.
           verfication code is required.
           first name is required.";
                        
              
        $error = preg_replace('/(\n)+\s+/m', '\n', $error);
?>