【发布时间】:2015-04-30 13:28:15
【问题描述】:
我的复选框有问题:它没有更新到数据库。
$emailnotification = new Zend_Form_Element_Checkbox('emailnotification ', 'emailnotification', array(
'checkedValue' => 1,
'uncheckedValue' => 0,
) );
$emailnotification->setLabel('emailnotification');
$emailnotification->setValue(1);
$this->addElement($emailnotification);
在控制器上,我有更新以下代码的操作:
if($this->_request->isPost())
{
$formData = $this->getRequest()->getPost();
if($form->isValid($formData))
{
$contact = new Admin_Model_DbTable_Contact();
$data = array();
$data['idContact'] = $idContact;
$data['firstname'] = $form->getValue('firstname');
$data['lastname'] = $form->getValue('lastname');
$data['emailnotification'] = $form->getValue('emailnotification');
if($contact->editContact($data))
{
echo json_encode(array(
"response" => true,
"message" => "Contact " . $data['firstname'] . " " . $data['lastname'] . "a été modifié"
));
exit();
} else {
echo json_encode(array(
"response" => false,
"errorMessage" => "Il y a eu une erreur dans l'edition de Contact."
) );
exit();
}
}
}
函数编辑联系人:
public function editContact(array $data) { if(!empty($data)) { if($this->update($data, array('idContact = ?' => $data['idContact'])) > 0 ) { return true; } return false; } return false; }
在.phtml上
$('#editContact').submit(function(event)
{
var formId = $(this).attr('id');
// Stop full page load
event.preventDefault();
//Request
var data = {
// contact's properties
firstname : $("#firstname").val(),
lastname : $("#lastname").val(),
emailnotification : $("#emailnotification").val(),
batnotification : $("#batnotification").val()
};
// Send
$.ajax({
url: $('#'+formId).attr('action'),
dataType: 'json',
type: 'POST',
data: data,
success: function(data, textStatus, XMLHttpRequest)
{
if (data.response == true)
{
alert(data.message);
//upContent('userManagement/index/','');
}
else
{
alert(data.message);
}
对我不起作用总是消息未定义且不更新数据库
提前致谢
【问题讨论】:
-
您能告诉我们您控制器中的代码吗?和整个表格?将表单中的值保存到数据库中的脚本在哪里?
-
$data['emailnotification'] = $form->getValue('emailnotification');
-
你能在我的代码中看到提前谢谢
-
你能在
Admin_Model_DbTable_Contact中显示方法editContact吗? -
公共函数 editContact(array $data) { if(!empty($data)) { if($this->update($data, array('idContact = ?' => $data[ 'idContact'])) > 0 ) { return true; } 返回假; } 返回假; }
标签: php zend-framework zend-form-element