2010-07-05 79 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