Welcome Guest, Not a member yet? Register   Sign In
Validation
#4

(This post was last modified: 08-17-2020, 09:12 AM by jreklund.)

Because you are redirecting, killing your data.
PHP Code:
if($validation->run())
      {

          
redirect()->to('user/pannello_user');

      } 

I think you can use withInput() but then you need to use the old() function as well or use the form_helper for everything.
https://codeigniter.com/user_guide/gener...l#redirect
https://codeigniter.com/user_guide/gener...s.html#old

Take a look at the tutorial.
https://codeigniter.com/user_guide/tutorial/index.html
PHP Code:
public function create()
{
    
$model = new NewsModel();

    if (
$this->request->getMethod() === 'post' && $this->validate([
            
'title' => 'required|min_length[3]|max_length[255]',
            
'body'  => 'required'
        
]))
    {
        
$model->save([
            
'title' => $this->request->getPost('title'),
            
'slug'  => url_title($this->request->getPost('title'), '-'TRUE),
            
'body'  => $this->request->getPost('body'),
        ]);

        echo 
view('news/success');

    }
    else
    {
        echo 
view('templates/header', ['title' => 'Create a news item']);
        echo 
view('news/create');
        echo 
view('templates/footer');
    }

Reply


Messages In This Thread
Validation - by pippuccio76 - 08-04-2020, 12:08 PM
RE: Validation - by jreklund - 08-04-2020, 12:25 PM
RE: Validation - by pippuccio76 - 08-17-2020, 06:47 AM
RE: Validation - by jreklund - 08-17-2020, 09:09 AM
RE: Validation - by pippuccio76 - 08-17-2020, 09:57 AM
RE: Validation - by jreklund - 08-21-2020, 11:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB