Php zend framework 1上的复选框出现问题

Php zend framework 1上的复选框出现问题,php,zend-framework,zend-form-element,Php,Zend Framework,Zend Form Element,我有一个复选框问题:它不会更新到数据库 $emailnotification = new Zend_Form_Element_Checkbox('emailnotification ', 'emailnotification', array( 'checkedValue' => 1, 'uncheckedValue' => 0, ) ); $emailnotification->setLabel('emailnotification'); $emailnoti

我有一个复选框问题:它不会更新到数据库

$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);
            }
不适用于我始终消息未定义且不更新数据库


提前感谢

我发现您的代码有一些问题,保存数据可以简化,因此我给您举一个示例,说明如何设置
editContact
方法。验证显然应该在表单本身中完成。请记住,数据库表和字段名可能与您的环境不同

// Admin_Model_DbTable_Contact
public function editContact( array $data )
{
    Zend_Registry::get( 'db' )->update(
        'contact_table',
        $data,
        'contact_id = ' . intval( $data['idContact']
    );
    return Zend_Registry::get( 'db' )->lastInsertId();
}
您还可以稍微优化控制器代码:

// In controller action
if($this->_request->isPost() && $form->isValid( $formData ) )
{
    $contact = new Admin_Model_DbTable_Contact();
    if( $contact->editContact( $form->getValues() + array( 'idContact' => $idContact ) ) ) {
    {
        echo json_encode(array(
            "response"   => true,
            "message"    => "Contact {$form->getValue( 'firstname' )} {$form->getValue( 'lastname' )} a été modifié"
        ) );
    } else {
        echo json_encode(array(
            "response"     => false,
            "errorMessage" => "Il y a eu une erreur dans l'edition de Contact."
        ) );
    }
    exit();
}

你能给我们看看你控制器里的代码吗?整个表格呢?将表单中的值保存到数据库的脚本在哪里?$data['emailnotification']=$form->getValue('emailnotification');你能在我的代码中看到吗提前谢谢你能在
Admin_Model_DbTable_Contact
中显示方法
editContact
?公共函数editContact(数组$data){if(!empty($data)){if(!empty($data)){if($this->update($data,array('idContact=?')=>$data['idContact'])>0){return true;}return false;}return false;}return false;}