如何在codegniter

时间:2015-11-09 11:54:31

标签: php codeigniter

如何检查控制器中以下字段的重复。 这是我的观看代码

            <div class="form-group col-lg-12">
            <label class="control-label col-lg-2">Name</label>
            <div class="col-lg-4">
                <select id ="choose" class="form-control" name="name">
                    <option value="">Select One</option>
                    <option value="create_user">New user creation</option>
                    <option value="register_user">New user registration</option>
                    <option value="forgot_password">Forgot Password</option>                        
                </select>
            </div>
            <div class="col-lg-6" id="email_tmpl"></div>
            </div>

            <div class="form-group col-lg-12">
            <label class="control-label col-lg-2">Notification to</label>
            <div class="col-lg-10">
                <select id ="notification" class="form-control" name="notification">
                    <option value="">Select One</option>
                    <option value="User">User</option>
                    <option value="Site Admin">Site Admin</option>
                </select>
            </div>
            </div>

如果我选择了选项&#34;新用户创建&#34;在第一个组合框中,然后我选择了#34;用户&#34;下一个组合框中的选项。 我想在再次选择&#34; User&#34;时显示错误消息。 &#34;新用户创建&#34;。仅限&#34;网站管理员&#34;可以选择&#34;新用户创建&#34;选项。 这是我的控制器代码。

    public function save_email_tmpl()
    {
    $this->load->model("Email_templates");
    $user_data = $this->session->userdata("logged_user");
    $post_data = $this->input->post();

    if($post_data != FALSE )
    {
    $check_name = $this->Email_templates->get_all_records
    ("",array("name" => $post_data["name"]));

        if(count($check_name)< 2)
        {

                $data = array("name" => $post_data["name"],
                    "notification" => $post_data["notification"],
                    "cc" => $post_data["cc"],
                    "subject" => $post_data["subject"],
                    "email_template" => $post_data["email"]);

        $this->Email_templates->insert_record($data,$user_data);
                echo json_encode(array(
                                "status" => "success",
                                "msg" =>  lang("email_tmpl_added")));

        }
        else
        {
            echo json_encode(array(
        "status" => "failed",
        "msg" => lang("invalid_data")));
        }
    }
    else
    {
        echo json_encode(array(
            "status" => "failed",
            "msg" => lang("invalid_data")));
    }
    }

我想检查此代码中的条件。

0 个答案:

没有答案