dongmei2956 2014-01-16 07:29
浏览 40

CodeIgniter - 唯一值 - 错误显示

I made a simple form, a newsletter subscription, which has two inputs: email and city. I use is_unique in form validation, but this error shows as text. I need to modify this text show in an alert box or warning.Need something to fix this error in design, suggestions please.

user.php controller

<?php 

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class User extends CI_Controller {

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

    public function create_user() {
        // field name, error message, validation rules
        $lang = $this->input->post("lang");
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]');
        $this->form_validation->set_rules('city', 'City', 'trim|required');
        if ($this->form_validation->run() == FALSE) {
            if ($lang == "en") {
                if ($this->agent->is_mobile()) {
                    $this->load->view('m_english_signup');
                } 
                else 
                {
                    $this->load->view('d_english_signup');
                }
                } //if ($this->agent->is_mobile())
            else 
            {
                if ($this->agent->is_mobile()) {
                    $this->load->view('m_arabic_signup');
                } 
                else 
                {
                    $this->load->view('d_arabic_signup');
                }
            }
        } 
        else 
        {
            $this->load->model('Users_model');
            if ($query = $this->Users_model->create_member()) {
                if ($lang == "en") {
                    if ($this->agent->is_mobile()) {
                        $this->load->view('m_english_thanks');
                    } 
                    else 
                    {
                        $this->load->view('d_english_thanks');
                    }
                } 
                else
                {
                    if ($this->agent->is_mobile()) {
                        $this->load->view('m_arabic_thanks');
                    } 
                    else 
                    {
                        $this->load->view('d_arabic_thanks');
                    }
                }
            }
        }
    }

}
  • 写回答

2条回答 默认 最新

  • dongzhong8691 2014-01-16 08:12
    关注

    You need to set your own error message ?

    try CodeIgnitor Userguide http://ellislab.com/codeigniter%20/user-guide/libraries/form_validation.html#settingerrors

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值