未验证CI表单

时间:2012-02-14 22:14:40

标签: php codeigniter

我正在试图弄清楚为什么当我运行这个控制器并且它试图运行表单时它不会验证它。有任何想法吗?每当我尝试提交表单时,它都会返回我的失败验证错误,提交表单时出现问题!请刷新窗口再试一次!

http://www.kansasoutlawwrestling.com/kowmanager/forgotpassword

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

 class Forgotpassword extends CI_Controller { 

public function __construct()
{
    parent::__construct();
    $this->load->library('kow_auth');  
    $this->load->model('kow_auth/users');           
}   

public function index()
{
    //Config Defaults Start
    $msgBoxMsgs = array();//msgType = dl, info, warn, note, msg
    $cssPageAddons = '';//If you have extra CSS for this view append it here
    $jsPageAddons = '<script src="http://www.kansasoutlawwrestling.com/kowmanager/assets/js/forgotvalidate.js"></script>';//If you have extra JS for this view append it here
    $metaAddons = '';//Sometimes there is a need for additional Meta Data such in the case of Facebook addon's
    $siteTitle = '';//alter only if you need something other than the default for this view.
    //Config Defaults Start


    //examples of how to use the message box system (css not included).
    //$msgBoxMsgs[] = array('msgType' => 'dl', 'theMsg' => 'This is a Blank Message Box...');

    /**********************************************************Your Coding Logic Here, Start*/

    if (!$this->session->userdata('xtr') == "yes") {
        $bodyContent = "forgot_password_form";//which view file
    } else {
        $bodyContent = "dashboard";//which view file
    }

    $bodyType = "full";//type of template

    /***********************************************************Your Coding Logic Here, End*/

    //Double checks if any default variables have been changed, Start.
    //If msgBoxMsgs array has anything in it, if so displays it in view, else does nothing.      
    if(count($msgBoxMsgs) !== 0)
    {
        $msgBoxes = $this->msgboxes->buildMsgBoxesOutput(array('display' => 'show', 'msgs' =>$msgBoxMsgs));
    }
    else
    {
        $msgBoxes = array('display' => 'none');
    }

    if($siteTitle == '')
    {
        $siteTitle = $this->metatags->SiteTitle(); //reads 
    }

    //Double checks if any default variables have been changed, End.

    $this->data['msgBoxes'] = $msgBoxes;
    $this->data['cssPageAddons'] = $cssPageAddons;//if there is any additional CSS to add from above Variable this will send it to the view.
    $this->data['jsPageAddons'] = $jsPageAddons;//if there is any addictional JS to add from the above variable this will send it to the view.
    $this->data['metaAddons'] = $metaAddons;//if there is any addictional meta data to add from the above variable this will send it to the view.
    $this->data['pageMetaTags'] = $this->metatags->MetaTags();//defaults can be changed via models/metatags.php
    $this->data['siteTitle'] = $siteTitle;//defaults can be changed via models/metatags.php
    $this->data['bodyType'] = $bodyType;
    $this->data['bodyContent'] = $bodyContent;
    $this->load->view('usermanagement/index', $this->data);
}

function forgot_password_submit()
{
    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');

    if (!$this->form_validation->run()) 
    {
        echo json_encode(array('error' => 'yes', 'message' => 'There was a problem submitting the form! Please refresh the window and try again!'));    
    }
    else
    {
        if (!is_null($user_data = $this->kow_auth->forgot_password($this->input->post('username')))) 
        {
            // Send email with password activation link
            $this->kow_auth->send_email('forgot_password', 'KOW Manager Forgot Password Email', $user_data);
        }   
    }          
}

}

/* End of file forgotpassword.php */ 
/* Location: ./application/controllers/forgotpassword.php */ 

1 个答案:

答案 0 :(得分:1)

您好像包含了一个不适用于此表单的jQuery Validation脚本。您链接到的页面的第66行是:

<script src="http://www.kansasoutlawwrestling.com/kowmanager/assets/js/forgotvalidate.js"></script>

哪个POST表单数据到以下URL:

http://www.kansasoutlawwrestling.com/kowmanager/register/register_submit

反过来,该页面会显示错误消息:

{"error":"yes","message":"There was a problem submitting the form! Please refresh the window and try again!"}

我假设您希望“忘记密码”页面自行发布(http://www.kansasoutlawwrestling.com/kowmanager/forgotpassword)。

您需要删除jQuery Validation脚本,或者修改它以使其与“忘记密码”页面一起使用。