Welcome Guest, Not a member yet? Register   Sign In
Problem with validation and 'trim'
#1

I'm using the validation library to validate the input received from an ajax request. I'm working through the tutorial, but converting to ajax, and moving the validations into the model. My validation rules look something like this:

PHP Code:
$validation->setRules([
            'title' => [
                'label' => 'Title',
                'rules' => 'trim|required|min_length[3]|max_length[128]'
            ],
            'body' => [
                'label' => 'Body',
                'rules' => 'trim|required|min_length[3]|max_length[65535]'
            ]
        ]); 

My validation is being run on an associative array of form elements grabbed from the ajax request:
PHP Code:
$validation->run($fields); 

This is generally working well, except for the trim. Leading and trailing spaces are being saved in the DB, and also leading spaces are being counted towards the string length, rendering the min_length[3] check as useless.

I can fix this by trimming all the inputs before running them through the validation rules, but my understanding was that the validation library was capable of doing this?
Reply


Messages In This Thread
Problem with validation and 'trim' - by Fido L Dido - 02-19-2020, 09:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB