CodeIgniter form_validation is not showing errors

Asked
Active3 hr before
Viewed126 times

9 Answers

showing
90%

Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers , How does the Bladesinging wizard's Extra Attack feature interact with the additional Attack action from the Haste spell? , By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. ,change to $this->load->helper(array('form','url')); public function auth() { $this->load->helper(array('form','url')); $this->load->library('form_validation'); $rules = array( array( 'field' => 'username', 'label' => 'username', 'rules' => 'required' ), array( 'field' => 'password', 'label' => 'Password', 'rules' => 'required' ) ); $this->form_validation->set_rules($rules); if ($this->form_validation->run() == false) { $this->load->view('form-new'); } else { echo ';) like a boss'; } }

one angle bracket is more in your code

public
function auth() {
   $this - > load - > helper(array('from', 'url'));

   $this - > load - > library('form_validation');

   $rules = array(
      array(
         'field' => 'username',
         'label' => 'username',
         'rules' => 'required'
      ),
      array(
         'field' => 'password',
         'label' => 'Password',
         'rules' => 'required'
      )
   );
   $this - > form_validation - > set_rules($rules);

   if ($this - > form_validation - > run() == false) {
      $this - > load - > view('login');
   } else {
      echo ';) like a boss';
   }
   `enter code here`
}
load more v
88%

CodeIgniter is a powerful PHP framework with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications.

function comment_insert() {
   $this - > load - > library('form_validation');

   // field name, error message, validation rules
   $this - > form_validation - > set_rules('author', 'author', 'trim|required');
   $this - > form_validation - > set_rules('comment', 'comment', 'trim|required');

   if ($this - > form_validation - > run() == FALSE) {
      redirect('blog/show_post/'.$_POST['entry_id']);
   } else {
      $this - > load - > model('blog_model');
      date_default_timezone_set('America/Los_Angeles');
      $data = array(
         'author' => $this - > input - > post('author'),
         'comment' => $this - > input - > post('comment'),
         'entry_id' => $this - > input - > post('entry_id'),
         'date' => date('Y-m-d-g-i-s'),
      );

      $this - > blog_model - > add_comment($data);
      redirect('blog/show_post/'.$_POST['entry_id']);

   }
}

function show_post() {
   $this - > load - > model('blog_model');
   $data = array();
   if ($query = $this - > blog_model - > get_post()) {
      $data['records'] = $query;
   }
   if ($query = $this - > blog_model - > get_comment()) {
      $data['comments'] = $query;
   }
   $data['main_content'] = ('post_view');
   $this - > load - > view('includes/template', $data);
}
load more v
72%

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL),If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.,Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. ,Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues

65%

I'm doing a project I'm using codeigniter form validation, but there was a problem, I put the check validations with an if but my error messages does not appear in the view as it should.,Form Validation of codeigniter is not showing error message ,** Remember in order to get the error validation never use redirect function. Use redirect function only when the validation was success.

Ci controller

    public
    function envia() {
       $this - > form_validation - > set_rules('nome', 'nome', 'required');
       $this - > form_validation - > set_rules('descricao', 'descricao', 'required');
       $this - > form_validation - > set_rules('preco', 'preco', 'required');
       if ($this - > form_validation - > run() == TRUE) {
          $produtos = array(
             "nome" => $this - > input - > post("nome"),
             "descricao" => $this - > input - > post("descricao"),
             "preco" => $this - > input - > post("preco"),
          );
          $this - > load - > model("produtos_model");
          $this - > produtos_model - > salva($produtos);
          redirect('/produtos/');
       } else {
          redirect('/produtos/novo');
       }

    }

View

    <div class="container">
       <div class="row">
          <?php echo validation_errors(); ?>
          <h2>Cadastro</h2>
          <?php echo form_open('produtos/envia');?>
          <div class="form-group">
             <?php
            echo form_label("Nome:", "nome");
            echo form_input(array(
                "name"  => "nome",
                "id"    => "nome",
                "class" => "form-control"
            ));
            ?>
          </div>
          <div class="form-group">
             <?php
            echo form_label("Descricao:", "descricao");
            echo form_input(array(
                "name"  => "descricao",
                "id"    => "descricao",
                "class" => "form-control"
            )); 
            ?>
          </div>
          <div class="form-group">
             <?php
            echo form_label("Pre?o:", "preco");
            echo form_input(array(
                "name"  => "preco",
                "id"    => "preco",
                "class" => "form-control"
            ));
            ?>
          </div>
          <div class="form-group">
             <?php
            echo form_submit(array(
                "class"   => "btn btn-primary",
                "value" => "Cadastrar"
            )); 
            ?>
          </div>
          <?php echo form_close();?>
load more v
75%

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.,After you ran the validation rules, what does,I enabled the error display, and updated the code. It now displays a long array list or something:,since it’s a function in the form helper, not a part of the form_validation library…

< ? php

class Form extends Controller {

   function Form() {
      parent::Controller();
      $this - > load - > helper('url');
      $this - > load - > helper('form');
      $this - > load - > library('form_validation');
   }

   function index() {
      //$this->load->helper(array('form', 'url'));

      $this - > form_validation - > set_rules('username', 'Username', 'required');
      $this - > form_validation - > set_rules('password', 'Password', 'required');
      $this - > form_validation - > set_rules('passconf', 'Password Confirmation', 'required');
      $this - > form_validation - > set_rules('email', 'Email', 'required');

      if ($this - > form_validation - > run() == FALSE) {
         $this - > load - > view('myform');
      } else {
         $this - > load - > view('formsuccess');
      }
   }
} ?
>
load more v
40%

$this - > form_validation - > set_rules('email', 'Email', 'trim|required|valid_email');
22%

Displaying Form Validation Error Messages ,Populating Submitted Form Data: Sticky Forms ,Validation solves the above problems. CodeIgniter Validation is done on two (2) fronts when working with web applications.,Following is a form submit in CodeIgniter example for validating the contact name

The following code shows the structure of a typical HTML form.

<form id="frmUsers" name="frmUsers" method="POST" action="create_user.php">
   <input type="text" id="user_id" name="user_id">
   <input type="password" id="password" name="password">

   <input type="submit" value="Submit">
</form>
load more v
60%

These are two ways to provide custom error messages.,In order to implement form validation you’ll need three things:,A controller method to receive and process the submitted data.,Although there is nothing terribly complex about the above process, it usually requires a significant amount of code, and to display error messages, various control structures are usually placed within the form HTML. Form validation, while simple to create, is generally very messy and tedious to implement.

<html>

<head>
   <title>My Form</title>
</head>

<body>

   <?= $validation->listErrors() ?>

   <?= form_open('form') ?>

   <h5>Username</h5>
   <input type="text" name="username" value="" size="50" />

   <h5>Password</h5>
   <input type="text" name="password" value="" size="50" />

   <h5>Password Confirm</h5>
   <input type="text" name="passconf" value="" size="50" />

   <h5>Email Address</h5>
   <input type="text" name="email" value="" size="50" />

   <div><input type="submit" value="Submit" /></div>

   </form>

</body>

</html>
load more v
48%

defined('BASEPATH') OR exit('No direct script access allowed');, <h2>Codeigniter Form Validation with Error Message - ItSolutionStuff.com</h2>,Form Validation is a primary requirement of every project, so i will give you simple example of form validation in codeigniter 3 application. we will use form_validation library for add form validation with error message display in codeigniter.,we can use default following validation rules of codeigniter 3:

< ? phpdefined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['item'] = "item/index";
$route['itemForm'] = "item/itemForm";
load more v

Other "showing-undefined" queries related to "CodeIgniter form_validation is not showing errors"