CodeIgniter Forums
Need help for CSRF/XSS and form validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: Need help for CSRF/XSS and form validation (/showthread.php?tid=74346)



Need help for CSRF/XSS and form validation - webdevron - 09-13-2019

1. In CI4, how to escape data during form submission? If i need to escape tags or CSS codes, how to do this? I want to work with HtmlSanitizer.

2. My validation rules are:
PHP Code:
$rules = [
    "inputName1" => "required",
    "inputName2" => "required",
    ........
];
if( ! 
$this->validate($rules) ) 
    return = array('FAILED!'json_encode($this->validator->getErrors())); 

a) How to set name for the each input in error message?
b) As i am submitting the form with AJAX, validation error always executing the success block with validation error message. Ajax is not getting the error headers. How to solve this?

3. How to set custom error header code and message in CI 4?

Thanks in advance and sorry for too many questions.


RE: Need help for CSRF/XSS and form validation - php_rocs - 09-13-2019

@webdevron,

1. does this help: https://codeigniter4.github.io/userguide/general/common_functions.html?highlight=esc%20function#esc
2. (a) try this: https://codeigniter4.github.io/userguide/libraries/validation.html?highlight=form%20validation#how-to-save-your-rules
(b) when the form is submitted what does it return?
3. try this: https://codeigniter4.github.io/userguide/libraries/validation.html?highlight=form%20validation#validation