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

(This post was last modified: 09-29-2020, 01:22 AM by Fil.)

Hi! I'm learning CI4, I have been using CI for a while but I figured out it's time to (try to) switch Wink

I'm facing some oddities in form validation


public function index(){

  echo view('templates/header', $output);
  echo view('pages/login.php'.$page, $output);
  echo view('templates/footer', $output);

public function login_user(){
    $validation = \Config\Services::validation();

      'user_email' => [
          'label'  => 'my_text_lang.text_formvalidation_email',
          'rules'  => 'trim|required'
      'user_password' => [
          'label'  => 'my_text_lang.text_formvalidation_password',
          'rules'  => 'trim|required'

    if ($validation->withRequest($this->request)->run() == FALSE) {
        return redirect('Login')->withInput();
        echo "test";

app/Views/pages/login.php have this code on top:
$validation = \Config\Services::validation();

      foreach ($validation->getErrors() as $error_description) {
        echo('<div class="alert alert-danger alert-dismissible fade show">'.$error_description.'<button type="button" class="close" data-dismiss="alert" aria-label="Close">
              <span aria-hidden="true">&times;</span>

app/Views/templates/header.php have this code on top: 
this is "if a user is logged in, use his language otherwise if hl=something is set in the url use that (or fallback to English) otherwise just use English"
    $request = \Config\Services::request();
    $lang = 'en';
        $userLanguage = session()->logged_user['userData']['language'];
        $lang = $this->config->languages[$userLanguage];
    }else if($request->getGet('hl') != null){
      switch ($request->getGet('hl')) {
        case '1':
          $lang = 'it';
          $lang = 'en';
      session()->sitelang = $lang;
    }else if(isset(session()->sitelang)){
          $lang = session()->sitelang;

    $language = \Config\Services::language();

$routes->get('/', 'Login::index');
$routes->add('Login', 'Login::index');

Oddities are:
1) the validation default messages are always localized in Italian. I have downloaded the "it" package from here https://github.com/codeigniter4/translations
and put that in the Lang folder. without it/Validation.php every validation message is in English, with the it/Validatio.php every message is in Italian.
I have labels in my login.php view that are showing correctly in English/italian (for instance <?=lang('my_text_lang.text_login_remember');?> ) so I think the code at the beginning of my header should work.
I have buttons/labels in English but validation errors in Italian...

2) redirect('Login')->withInput(); will bring me to //localhost:8888/MY_CI_PROJECT/public/index.php/Login instead of //localhost:[font=Monaco, Consolas, Courier, monospace]8888/MY_CI_PROJECT/public[/font]

3)I'm not completely sure about this but, after triggering the validation, if I manually change the URL to

//localhost:8888/MY_CI_PROJECT/public/Login something redirects me to 


opening a new browser and go to [font=Tahoma, Verdana, Arial, sans-serif][font=Monaco, Consolas, Courier, monospace]//localhost:8888[/font][font=Monaco, Consolas, Courier, monospace]/MY_CI_PROJECT/public/Login [/font][/font]doesn't do that... 

I'm developing with MAMP on macOS, htaccess file is the default one.


Theme © iAndrew 2016 - Forum software by © MyBB