Welcome Guest, Not a member yet? Register   Sign In
set_value In Codeigniter4
#1

how it works set_value In Codeigniter4 ? I call helper form but no works... 
Reply
#2

You will need to provide some code, so we can see why it's not working.
I can only refer to the manual at this time:
https://codeigniter4.github.io/userguide...#set_value
Reply
#3

(This post was last modified: 02-07-2020, 01:07 PM by jreklund.)

I think when I return to form the values ​​entered should be kept ... but it doesn't

----- Controller ----
PHP Code:
<?php namespace App\Controllers;

class 
Account extends BaseController
{
    
     function 
__construct(){
        
        
$session = \Config\Services::session($config);
        
$session->start();              
        
helper(['url''form']);          
     }

  
    public function 
index()
    {
      echo 
view('account/login-form');
    }   

    public function 
login(){
        
    
helper(['url''form']);        
      
    
$rules = [
              
'email' => ['label' => 'e-mail''rules' => 'required|valid_email'],
              
'password' => ['label' => 'senha''rules' => 'required'],
             ];
                   
      if(!
$this->validate($rules)){
          
       echo    
$listErros  =  \Config\Services::validation()->listErrors();
       return 
redirect()->to('/account/index');
       }
    }    


------ View -----
PHP Code:
<form action="<?php echo base_url(); ?>/account/login" method="post" >
 
 <
label for="email">e-mail:</label
 <
input type="text" name="email" value="<?php echo set_value('email'); ?>" >
 
 <
label for="password">senha:</label
 <
input type="password" name="password" value="<?php echo set_value('password'); ?>" >
 
 
 <
button>send! </button>
</
form
Reply
#4

(This post was last modified: 02-07-2020, 01:16 PM by jreklund.)

Haven't tested your code, but I think it's your redirect that's the problem. Your values aren't stored in $_POST after a redirect have been made. You need to run both the view and functionality in the same method.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB