如何在codeigniter中显示每个字段的成功消息

时间:2010-04-13 14:14:32

标签: validation

如何针对每个表单字段显示成功消息,就像我们显示每个字段的错误消息一样..当我写

<?if(form_error('username')) {
  //show error message
}
else
   // show success message
?>

在没有验证任何内容的情况下加载表单时显示成功消息..

2 个答案:

答案 0 :(得分:0)

与测试表单是否已经提交的方式几乎相同......(并且不要使用短标签)

<?php 
    if(form_error('username')) {
      //show error message
    } elseif (isset($_REQUEST['submit_button_value'])) {
       // show success message
    }
?>

答案 1 :(得分:0)

application / controllers / firstcontroller.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class firstcontroller extends CI_Controller {
   public function __construct() { 
      parent::__construct(); 
      $this->load->library("session");
   }
  public function success()
  {
      $this->session->set_flashdata('success', 'User Updated successfully');
      return $this->load->view('myPages');





<!DOCTYPE html>
<html>
<head>
  <title>Pages for Alert</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet" />
</head>
<body>
<div>
  <?php
    $this->load->view('alert');
  ?>
</div>
</body>

了解更多:https://www.phpcodingstuff.com/blog/how-to-show-success-message-in-codeigniter.html