2010-07-05 80 views
0

我嘗試在笨的形式來設置密碼... 一切似乎確定以我的眼睛,但不管我用哪個密碼的形式仍然是提交...codeigniter設置密碼!

這裏是在CONTROLER的代碼:

class MyBlog extends Controller{ 


    function MyBlog(){ 
     parent::Controller(); 
     $this->load->helper(array('url','form','html')); //here we load some classes that we use 

     $this->load->scaffolding('entries'); //scaffolfing is a feature that lets you add or remove elements from the database 
     $this->load->scaffolding('comments'); 

     $this->load->library('form_validation');//load validation class used to validate our forms... 
    } 

    function index(){ 

     $data['title'] = "My Blog Title"; //the title of my blog 
     $data['query'] = $this->db->get('entries'); //here we make a small query to entries table 


     $this->load->view('myBlog_view', $data); ///load all data variables on myBlog_view.php 
    //this is also for the form validation 


     $this->form_validation->set_rules('title', 'Title', 'required'); 
     $this->form_validation->set_rules('body', 'Body', 'required'); 
     $this->form_validation->set_rules('author', 'Author', 'required'); 
     $this->form_validation->set_rules('pass', 'Pass', 'callback_pass_check'); 


     function pass_check($str) { 
     if ($str == 'baywatch'){ 
      return TRUE; 
     } 
     else{ 
      return FALSE; 
     } 
    } 



     if ($this->form_validation->run() == TRUE) 
     { 


      $this->myBlog_insert(); 
      //$this->load->view('formSuccess_view'); 
     } 

     } 



function myBlog_insert(){ 

     $insert = array('title' => $_POST['title'], 
         'body' => $_POST['body'], 
         'author' => $_POST['author'] 
         ); 

     $this->db->insert('entries',$insert); 

     redirect('myBlog/'); 
     } 


} 

,這是我的表單:

<div class="theForm"> 

<?php echo $this->form_validation->error_string; ?> 
<?php echo validation_errors(); ?> 
<?php echo form_open('myBlog'); ?> 


<label for="title">Title:</label> 

<input type='text' name="title" size="40" id="title" /> 
<p> 
<label for="body">Body:</label> 
<textarea name="body" rows = "10" cols="60" id="body"></textarea> 
</p> 
<p> 
<label for="author">Author:</label> 
<input type="text" name="author" size="40" id="author"/> 
</p> 
<p> 
<label for="pass">Password:</label> 
<input type="password" name="pass" size="38" id="pass"/> 
</p> 
<p><input type="submit" value="Submit New Post"/></p> 
</form> 
</div> 
</body> 
</html> 

什麼想法? 由於事先

回答

0

好吧......我發現問題是什麼......函數pass_check在index()中聲明...出於某種原因它需要作爲類的一個方法在外面...希望這會幫助其他人...我給所有的建議一些ups ...

+0

當然。發現得好!不能相信我錯過了... – musoNic80 2010-07-05 19:45:59

1
<label for="pass">Password:</label> 
<input type="text" name="pass" size="38" id="author"/> 

輸入類型是文本沒有密碼,該ID =「通過」。

+0

我改變了類型爲「密碼」仍然沒有運氣...謝謝反正 – rabidmachine9 2010-07-05 18:17:58

1

好吧,首先有幾件事:

1)id的應該是唯一的。即您的作者字段和您的密碼字段不應該有相同的ID。 2)密碼文件應該使用「密碼」而不是「文本」類型。

我認爲你有問題的原因是你的回調函數pass_check()。嘗試將您的功能更改爲:

function pass_check($pass) 
{ 
if($pass !== 'baywatch') 
{ 
    return FALSE; 
} 

順便說一下,腳手架現在已被棄用。我可以建議你看看使用模型和活動記錄類作爲與你的數據庫交互的方式嗎?另外,這真的不是處理密碼的非常安全的方式。查看一些CI身份驗證庫並查看是否可以實現其中的一個。

+0

謝謝你的所有建議...我改變了pass_check代碼,但仍然沒有完成這項工作......(我不認爲這兩個函數在某種程度上有任何真正的區別......)無論我輸入什麼格式,仍然會提交表單。 – rabidmachine9 2010-07-05 19:02:55

+0

這兩個函數基本相同。我嘗試傳遞字段名稱作爲參數,看看是否有幫助,並簡化了一些語法。 – musoNic80 2010-07-05 19:46:57