Welcome Guest, Not a member yet? Register   Sign In
Validate multiple input in CI 4
#1
Sad 

Hi,

This is the code in my controller:

PHP Code:
$fields = array(
    "user_id[]" => "required"
);

print_r($this->request->getPost("user_id"));

$final_fields = array();

//to remove the fields if the post request doesn't found
foreach ($fields as $field => $validate) {
    if (!is_null($this->request->getPost($field))) {
        $final_fields[$field] = $validate;
    }
}

if (!
$final_fields) {
    return true;
}

$validate $this->validate($final_fields);

if (!
$validate) {
    $validation = \Config\Services::validation();
    $message $validation->getErrors();
    echo json_encode($message);
    exit();


I'm getting this output:

Code:
Array
(
    [0] => 7
    [1] => 17
)
{"user_id[]":"The user_id[] field is required."}

Looking for help. 
Thanks in advance.
Reply


Messages In This Thread
Validate multiple input in CI 4 - by ciddict - 03-10-2021, 11:35 AM
RE: Validate multiple input in CI 4 - by demyr - 03-11-2021, 12:25 AM
RE: Validate multiple input in CI 4 - by ciddict - 03-11-2021, 12:57 AM
RE: Validate multiple input in CI 4 - by InsiteFX - 03-11-2021, 02:16 AM
RE: Validate multiple input in CI 4 - by ciddict - 03-11-2021, 02:49 AM
RE: Validate multiple input in CI 4 - by kenjis - 03-11-2021, 03:15 PM
RE: Validate multiple input in CI 4 - by ciddict - 03-12-2021, 07:20 AM
RE: Validate multiple input in CI 4 - by kenjis - 03-12-2021, 10:19 PM
RE: Validate multiple input in CI 4 - by ciddict - 03-13-2021, 02:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB