Welcome Guest, Not a member yet? Register   Sign In
I want to return the value entered by the user at the time of validation error
#1
Smile 

## overview
where is 'set_fields'.

## reference
https://codeigniter4.github.io/userguide...ation.html

## detail
The Codeigniter 3 Tutorial had a special variable called 'set_fields'.
The effect was to display the 'post' data entered by the user.

Now, when I have a simple "create lesson" controller like this, is there a way to keep the values entered by the user?
or should I assign it to '$ _POST' and use 'post' in the template?

PHP Code:
    /**
    * @throws ReflectionException
    */
    public function create(): RedirectResponse|string
    
{
        $data null;
        if ($this->request->getMethod() === 'post') {
            $this->validation->reset();
            if ($this->validate(
                [
                    'lesson_title' => ['label' => 'title''rules' => 'required'],
                ]
            )) {
                // valid
                $isContinuous $this->request->getPost('is_continuous');
                if (isset($isContinuous)) {
                    return redirect('lesson_create');
                } else {
                    return redirect('lesson_list');
                }
            } else {
                // invalid
                $data['validation'] = $this->validator;
                view(route_to('lesson_create'), $data);
            }
        } else {
            $data = [
                'title' => null,
                'body' => null,
            ];
        }
        
        $b 
= new Breadcrumb();
        $b->add('Home'route_to('school_home'));
        $b->add('lesson manage'route_to('lesson_list'));
        $b->add('lesson create'null);
        $data['breadcrumb'] = $b->render();
    
        
return view(route_to('lesson_create'), $data);
    
Reply


Messages In This Thread
I want to return the value entered by the user at the time of validation error - by yoshi - 04-09-2022, 07:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB