2012-09-12 19 views
0

我想在登錄操作之前將我在auth組件中使用的用戶名和密碼字段轉換爲大寫字母。我試圖設置如何在auth組件中大寫登錄字段 - cakephp

text-transform:uppercase; 

在我的CSS,輸入,它的工作。但是大寫的信息不會進入數據庫。如果我用大寫鎖定字符串,這些字符串只會被大寫。有人能給我一個例子(對於新手)嗎?

謝謝!

編輯:

這裏是我的登錄操作:

function login() { 

if (!empty($this->data) && $this->Auth->user()) { 
    $this->User->id = $this->Auth->user('id'); 
    $this->User->saveField('last_login', date('Y-m-d H:i:s')); 
    $this->redirect($this->Auth->redirect()); 
} 

}

+0

應該如果運作它在正確的位置。你將不得不提供更多的代碼。 – sonjz

+0

它可以在視覺上工作......但大寫的用戶名和密碼不是數據庫(firebird)正在接收的內容,因爲登錄不起作用(數據庫中的所有用戶名和密碼都是大寫的)。但如果我用CAPSLOCK編寫用戶名和密碼,一切正常。 – qxlab

+0

它是蛋糕2.x還是1.3? – bfavaretto

回答

1

您可以在服務器端PHP大寫通過@thecodeparadox作爲證明,或者您也可以與客戶端 - 這樣做方javascript或如果您使用jQuery,將其添加到您的事件。

HTML/JavaScript的:

<form> 
    <input type="text" name="username" onchange="this.value = this.value.toUpperCase();" /> 
    <input type="password" name="password" onchange="this.value = this.value.toUpperCase();" /> 
</form>​ 

演示:http://jsfiddle.net/85HEy/2/

或HTML/jQuery的:

<form> 
    <input type="text" name="username" /> 
    <input type="password" name="password" /> 
</form> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script> 
<script> 
    $(document).ready(function() { 
    $("input[name='username'], input[name='password']").change(function() { 
     $(this).val($(this).val().toUpperCase()); 
    }); 
    }); 
</script>​ 

演示:http://jsfiddle.net/T9XbP/

+0

謝謝你的想法。我把我的login.ctp:echo $ form-> input('username',array('onchange'=>'this.value = this.value.toUpperCase()')); – qxlab

+0

不客氣,是不是cakephp很棒? :) – sonjz