首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >代码点火器形式验证不显示错误

代码点火器形式验证不显示错误
EN

Stack Overflow用户
提问于 2016-02-29 13:39:27
回答 2查看 116关注 0票数 0

我正在使用我的本地机器上的一个wamp服务器,来主持我的代码点火器项目。一切看起来都很好,但是表单验证不会在错误发生时显示出来。查看电子邮件是否已经存在的回调也不起作用,这真的很奇怪,因为它昨晚起作用了。

这是我的控制器-

代码语言:javascript
复制
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Signup extends MX_Controller
{

function __construct() {
parent::__construct();

            //calling helpers and library classes from ci
                            $this->load->helper(array('form', 'url'));
                            $this->load->helper('date');
                            $this->load->library('form_validation');
        }

public function index() {





             // loading the registration form
                $this->load->view('register');

                // form validation
                $this->form_validation->set_rules('username', 'Username', 'required|min_length[3]|max_length[12]|is_unique[gamers.username]');
                $this->form_validation->set_rules('email','Email','trim|required|valid_email|callback_isEmailExist');
                $this->form_validation->set_rules('country', 'Country', 'required');
                $this->form_validation->set_rules('region', 'Region', 'required');
                $this->form_validation->set_rules('dob', 'Birth Date', 'required');
                $this->form_validation->set_rules('phone', 'Mobile Number', 'required');
                $this->form_validation->set_rules('passphrase', 'Password', 'trim|required|sha1');
                $this->form_validation->set_rules('referral', 'Referred By');




     if ($this->form_validation->run() !== FALSE)
                {
                     //loading model
                      $this->load->model('signup_model'); 

                    // preparing form data
                     $username  = $this->input->post('username');
                     $email     = $this->input->post('email');
                     $country   = $this->input->post('country');
                     $region    = $this->input->post('region');
                     $dob       = $this->input->post('dob');
                     $phone     = $this->input->post('phone');
                     $password  = $this->input->post('passphrase');
                     $referred  = $this->input->post('referral');
                      //check current time stamp
                     $join_date = date('Y-m-d H:i:s');
                      //email verification hush key-generator
                     $token = md5(rand(0,1000).'cashout233');


                    // packaging form data for transport in an array

                            $data = array(
                            'username'        => $username,
                            'email'           => $email,
                            'country'         => $country,
                            'region'          => $region,
                            'birthdate'       => $dob,
                            'phone_number'    => $phone,
                            'password'        => $password,
                            'join_date'       => $join_date,
                            'referral'        => $referred,
                            'token'           => $token

                );


                    // finally  transporting data to the model

                   $taxi = $this->signup_model->register_gamer($data);

                   if ($taxi !== false) {

                             // send email verification link after sucessfull transport
                  //  $from    = 'noreply@talenthut.com';
                  //  $to      =  $email; 
                  //  $subject = 'Email Confirmation Instructions'; 
                   // $message = '

                   // '.$first_name.',  Thanks for signing up!

                   // Please click this link to activate your account:
                    // localhost/index.php/email_verification?email='.$email.'&hash='.$hash.'

                   //  '; // Our message above including the link

                  //   $this->email->from($from);
                 //    $this->email->to($email);

                 //    $this->email->subject($subject);
                  //   $this->email->message($message);

                  //   $this->email->send();

                    // Redirect user to Email Confirmation Page

                    redirect('index.php/signup/EmailConfirmation/'.urlencode($email));


                    } 


                }


                }

public function isEmailExist($str) {

    $this->load->model('signup_model');
    $is_exist = $this->signup_model->isEmailExist($str);

    if ($is_exist) {
        $this->form_validation->set_message(
            'isEmailExist', 'Email address is already in use.'
        );    
        return false;
    } else {
        return true;
    }
}
public function EmailConfirmation($to)
    {

      echo "email has been sent to ".urldecode($to);
              // loading the email confirmation page
               // $this->load->view('e_confirmation');


}

}

我认为显示登记表的是-

代码语言:javascript
复制
<?php echo form_open('index.php/signup'); ?>

 <!-- fieldsets -->
                <fieldset>

 <div class="errors"> <?php echo validation_errors();  ?> </div>
<label>

 <input id="username" type="text" name="username" value=""  placeholder="Username" />

</label>


<label>
<input id="email" type="email" name="email" value=""  placeholder="Email" />

</label>

<label>
                    <select name="country"><br/>
                    <option value="Ghana">Ghana</option>
                    </select> 
</label>
    <label>
                    <select name="region"><br/>
                    <option value="">Choose Region...</option>
                    <option value="Greater Accra">Greater Accra</option>
                    <option value="Central">Central</option>
                    <option value="Western">Western</option>
                    <option value="Eastern">Eastern</option>
                    <option value="Ashanti">Ashanti</option>
                    <option value="Brong Ahaful">Brong Ahaful</option>
                    <option value="Northen">Northen</option>
                    <option value="Volta">Volta</option>
                    <option value="Upper East">Upper East</option>
                    <option value="Upper West">Upper West</option>
                    </select> 

    </label>

<label>

 <input id="dob" type="text" name="dob" value=""  placeholder="Birth Date" />

</label>
<label>

 <input id="phone" type="text" name="phone" value=""  placeholder="Mobile Number" />

</label>

<label>

<input id="password" type="password" name="passphrase" value=""  placeholder="Password" />

 </label>

    <label>
                    <select name="referral"><br/>
                    <option value="">how did you know about us</option>
                    <option value="Search Engine">Search engine</option>
                    <option value="Twitter">Twitter</option>
                    <option value="Word of Mouth">Word of mouth</option>
                    <option value="Newspaper">Newspaper</option>
                    </select> 

    </label>


 <label>
    <span>&nbsp;</span>
 <p class="help">By clicking the sign up button below, you confirm that you are 18 years , and you agree to our
                        <a href="/help/terms.php" target="_blank">Terms and Conditions</a> and <a href="/help/privacy.php" target="_blank">Privacy Policy</a>.</p><br/><br/>

 <span>&nbsp;</span>

<button class="submit" type="submit">Sigm Up</button>

</label> 

</fieldset>

</form>

isEmailExist控制器函数的模型函数是

代码语言:javascript
复制
function isEmailExist($email) {
    $this->db->select('id');
    $this->db->where('email', $email);
    $query = $this->db->get('gamer');

    if ($query->num_rows() > 0) {
        return true;
    } else {
        return false;
    }
}

提前谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-02-29 16:10:34

解决了!

我意识到验证并不适用于重定向,而只适用于视图。

在验证之前,我还过早地调用了登录表单。我把它放在了假设条件下,一切都很有魅力。

至于“回调”。我只需要消除所有这些胡说八道,用is_unique取代它。

票数 0
EN

Stack Overflow用户

发布于 2016-07-20 05:27:13

您可以检查电子邮件是否存在,只需简单地应用代码点火器内置规则:

is_uniquetable_name.table_coloum

代码语言:javascript
复制
$this->form_validation->set_rules('email', 'Email', 'required|trim|xss_clean|is_unique[users.email]');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35701043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档