PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 13, 2022

[FIXED] How to show validation errors in the single message Codeigniter?

 July 13, 2022     codeigniter, message, show, validation     No comments   

Issue

I have a problem with codeigniter, when checking the fields it shows errors as follows:

The Username field is required. The Password field is required. 
The Another field is required

but I need it so like this:

Required fields a Username, Password, Another.

How to do it?


Solution

I wouldn't do that. But you have numerous number of choices. For example: don't use form validation library at all or develop your own. Try something like this:

$errorArray = array();
if (!$this->input->post('username')) {
    $errorArray[] = 'Username';
}
if (!$this->input->post('Password')) {
    $errorArray[] = 'Password';
}
if (count($errorArray)!==0) {
    $allErrorFields = implode(",", $errorArray);
    $errorMessage = 'Required fields: '.$allErrorFields;
    $data['errorMessage'] = $errorMessage;
}

$this->load->view('myview', $data);


Answered By - cssBlaster21895
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing