Welcome Guest, Not a member yet? Register   Sign In
How to display an array of errors when working with redirect() in Codeigniter?
#1
Lightbulb 

I created a form to add a product on Codeigniter. The form works fine, but I can't fully configure the validation.
The Products controller, which has the add_form() method, is responsible for processing the product addition form.
In this method, at the very beginning I check the validity of the fields.
PHP Code:
$validationRule = [
            'name_product' => [
                'label'  => 'Product name',
                'rules'  => 'required|max_length[256]',
                'errors' => [
                    'required' => "Field '{field}' required",
                ]
            ],
            'price_product' => [
                'label'  => 'Price',
                'rules'  => 'required|is_natural',
                'errors' => [
                    'is_natural' => "F Field '{field}' must be a number",
                    'required'  => "Field '{field}' required",
                ]
            ],
 ];

$validation =  \Config\Services::validation();
$validation->reset();
$validation->setRules($validationRule);

if (!
$validation->run($dataQuery)) {
    $arrErrors $validation->getErrors();

    return redirect()->back()->withInput()->with('errors'$arrErrors);




In general, everything works, but I can’t display a list of errors in the form view!

I don't understand how to display the data passed to the ->with('errors', $arrErrors) method
Reply
#2

See https://codeigniter4.github.io/userguide...ion-errors
Simple CI 4 project for beginners codeigniter-expenses
Reply




Theme © iAndrew 2016 - Forum software by © MyBB