我正在我的第一個cakephp應用程序。 Auth和原始驗證工作正常。CakePHP就地編輯數據庫與驗證
我對用戶的私人頁面進行了一些修改,其中顯示的個人數據,我使它能夠使用jQuery + jEditable編輯數據,完美工作。
我的問題是,當我修改例如電子郵件到一個壞的,我的意思是「someone @ .com」或「[email protected]」。所以我認爲你可以讓我的應用程序不能在就地修改數據時使用「驗證」。
我會對所有字段進行驗證:不是空的,正確的電子郵件語法和新的密碼與md5哈希生成和密碼確認以某種方式。
你會看到一切正常,但密碼不是,我沒有任何想法如何做確認字段和md5哈希生成。
如果你能幫助我一點,我將不勝感激。
我也會知道這個安全性,我必須注意什麼?
這裏是代碼:
UsersController.php
public function in_place_editing($id = null) {
if (!$id) return;
if ($this->request->data) {
# get all the fields with its values (there should be only one, but anyway ...)
foreach($this->data['User'] as $field => $value)
{
# check if the provided field name is acceptable
switch($field)
{
case 'email':
case 'postcode':
case 'city':
case 'address':
case 'phone':
break;
default:
$this->set('updated_value', '');
return;
}
$this->User->id = $id;
$this->User->save($field, $value);
$this->set('updated_value', $value);
$this->beforeRender();
$this->layout = 'ajax';
}
}
}
index.ctp(這是私人DATAS頁)
<h2>Personal details</h2>
<table cellpadding="0" cellspacing="0">
<tr>
<td>Name</td>
<td><?php echo $userdata[0]['User']['name']; ?></td>
</tr>
<tr>
<td>E-mail</td>
<td>
<?php
echo $this->inPlaceEditing->input('User', 'email', $userdata[0]['User']['id'],
array('value' => $userdata[0]['User']['email'],
'actionName' => 'users/in_place_editing',
'type' => 'text',
'cancelText' => 'Cancel',
'submitText' => 'Save',
'toolTip' => 'Click to edit',
//'containerType' => 'td'
)
);
?>
</td>
</tr>
<tr>
<td>Postcode</td>
<td>
<?php
echo $this->inPlaceEditing->input('User', 'postcode', $userdata[0]['User']['id'],
array('value' => $userdata[0]['User']['postcode'],
'actionName' => 'users/in_place_editing',
'type' => 'text',
'cancelText' => 'Cancel',
'submitText' => 'Save',
'toolTip' => 'Click to edit',
//'containerType' => 'td'
)
);
?>
</td>
</tr>
<tr>
<td>City</td>
<td>
<?php
echo $this->inPlaceEditing->input('User', 'city', $userdata[0]['User']['id'],
array('value' => $userdata[0]['User']['city'],
'actionName' => 'users/in_place_editing',
'type' => 'text',
'cancelText' => 'Cancel',
'submitText' => 'Save',
'toolTip' => 'Click to edit',
//'containerType' => 'td'
)
);
?></td>
</tr>
<tr>
<td>Address</td>
<td>
<?php
echo $this->inPlaceEditing->input('User', 'address', $userdata[0]['User']['id'],
array('value' => $userdata[0]['User']['address'],
'actionName' => 'users/in_place_editing',
'type' => 'text',
'cancelText' => 'Cancel',
'submitText' => 'Save',
'toolTip' => 'Click to edit',
//'containerType' => 'td'
)
);
?>
</td>
</tr>
<tr>
<td>Phone number</td>
<td>
<?php
echo $this->inPlaceEditing->input('User', 'phone', $userdata[0]['User']['id'],
array('value' => $userdata[0]['User']['phone'],
'actionName' => 'users/in_place_editing',
'type' => 'text',
'cancelText' => 'Cancel',
'submitText' => 'Save',
'toolTip' => 'Click to edit',
//'containerType' => 'td'
)
);
?>
</td>
</tr>
</table><br>
<h2>User and password</h2>
<table cellpadding="0" cellspacing="0">
<tr>
<td>Username</td>
<td><?php echo $userdata[0]['User']['username']; ?></td>
</tr>
<td>Password</th>
<td>Modify</td>
</tr>
</table>
謝謝你在前進, 最好的問候, Krisztian
遺憾的UsersController.php行:「$這個 - >用戶 - >保存($ field,$ value);「是「$ this-> user-> saveField($ field,$ value);」 只是一個小的校正爲清晰的視線 – user1819486 2013-04-24 10:31:57