• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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
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
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.