zend / ajax与动态添加行有关的问题

时间:2014-01-23 09:29:42

标签: jquery mysql zend-framework

我有3个表,包括要选择的输入和第4个表,其中3个表的id作为该表中的外键,也是两列,其中包含输入.4个表依赖于每个表其他。我使用下拉菜单,例如选择大陆dropwns自动填充,国家/“省/州”/城市等,也是存储此信息的第5个表。我想知道如何获取这些选定的变量并将它们保存在第5个表中。使用zend / ajax / jquery

我维护一个旧的数据库,但为它创建一个新的应用程序,然后他们使用纯PHP,然后说我的大脑感到迷茫。 我一直收到这个错误:在大海捞针中找不到933'/我认为它与验证有关

这是我的代码

Jquery的

<script type="text/javascript">
$(document).ready(function(){
    $('#add').click(function(){
          $.ajax({
               url:'<?php echo $this->baseURL()?>/ajax/postsic',
               type:'post',
               data:{'division':$('#div_des').val(),'majorgroup':$('#mgrp_desc').val(),'group':$('#grp_desc').val(),'sic description':$('#sic_description').val()},       
               success:function(data){
                 $('#t2').append(data);

              }
          });
    });
    });

    </script>

actioncontrollerajax

public function postsicAction()
{
    $form = new Form_SmmeDetails5();       
    $this->view->form = $form;

    if(!$form->isValid($_POST)) {
        $values=$form->getValues();

        $mdlSmme = new Model_Smmesic();
        $results = $mdlSmme->getSelected($selected); 

        $returndata ='<tr>';
        $returndata .='<td>'.$div_code.'</td>';
        $returndata .='<td>'.$mgrp_code.'</td>';
        $returndata .='<td>'.$grp_code.'</td>';
        $returndata .='<td>'.$sic_code.'</td>';

        $returndata .='<tr>';

        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender();

        echo $returndata;

        exit;
        if($form->isValid($_POST)) {
        } else {
            $form->populate($formData);
        }
    }
}

actioncontroller注册表单/下拉列表

public function register5Action()
{
    $this->view->headScript()->appendFile('/js/ui/jquery.ui.autocomplete.js');
     $form = new Application_Form_SmmeDetails5();

    //$form->submit->setLabel('Finish');
    $this->view->form = $form;

    if ($this->getRequest()->isPost()) {
        $formData = $this->getRequest()->getPost();
        if ($form->isValid($formData)) {                

            $sector_name = $form->getValue('sector_name');

            $div_desc = $form->getvalue ('div_desc');
            $mgrp_code = $form->getvalue ('mgrp_code');
            $grp_code = $form->getvalue ('grp_code');
            $sic_description = $form->getvalue ('sic_description'); 
            $description= $form->getvalue ('description');
            $comments = $form->getvalue ('comments');
            $core_product = $form->getvalue ('core_product');     


            //$sectors = new Application_Model_DbTable_Sectors();
            //$sectors->smmedetails5sectors($sector_name);

            //$smmesic = new Model_SmmeDetails5();
            //$smmesic ->smmedetails5smmesic ($div_desc, $mgrp_code, $grp_code, $sic_description, $description, $comments, $core_product);

            //$division = new Application_Model_DbTable_Division();
            //$division->smmedetails5division($div_desc);

            $this->redirect('/admin/index');
        } else {
            $form->populate($formData);
        }
    }
}

模特smmesic

public function getSelected($selected) 
{
    $select = $this ->select()
                        ->from('division')
                        ->where('id = ?', $div_code);

    $select = $this ->select()
                        ->from('majorgroup')
                        ->where('id = ?', $mgrp_code);

    $select = $this ->select()
                        ->from('group')
                        ->where('id  = ?', $grp_code);

    $select = $this ->select()
                        ->from('siccode')
                        ->where('id = ?', $sic_code);   

    return $this->fetchAll($select);
}

我的表格

<?php

class Application_Form_SmmeDetails5 extends Zend_Form
{

    public function init()
    {
        //$required = new Zend_Validate_NotEmpty ();
        //$required->setType ($required->getType() |  Zend_Validator_NotEmpty::NotEmpty );


        $this->setName('smmedetails5')
             ->setAttribs(array('class' => 'new_user_form'));
        $sector_id = new Zend_Form_Element_Hidden('sector_id');

        $sector_name = new Zend_Form_Element_Select('sector_name');     
        $sector_name ->setLabel('Sector')
                ->addMultiOption('--Select One--', '--Select One--');
                //->addValidators (array ($required));

        $mdlSectors = new Model_Sectors();
        $sectors = $mdlSectors->getSectors();       
        foreach ($sectors as $sector)
        {
            $sector_name->addMultiOption($sector->sector_id, $sector->sector_name);
        }  

        $sector_name->addDecorator(array('row' => 'HtmlTag'), array('tag' => 'div','class' => 'col-md-12 field-box'))
               ->addDecorators(array(array('HtmlTag',array('tag' => 'dd', 'class' => 'ui-select span5'))));


        $search = new Zend_Form_Element_Text('search');
        $search->setLabel('Search SIC Code:');


        $search->addDecorator(array('row' => 'HtmlTag'), array('tag' => 'div','class' => 'col-md-12 field-box'));           
        $search->setAttribs(array('class' => 'col-md-9 form-control')); 


        $div_desc = new Zend_Form_Element_Select('div_desc');       
        $div_desc  ->setLabel('Division')
                ->addMultiOption('--Select One--', '--Select One--');

        $mdlDivision = new Model_Division();
        $divisions = $mdlDivision->getdivisions();          
        foreach ($divisions as $division)
        {
            $div_desc->addMultiOption($division->div_code, $division->div_desc);
        } 

        $div_desc->addDecorator(array('row' => 'HtmlTag'), array('tag' => 'div','class' => 'col-md-12 field-box'))
             ->addDecorators(array(array('HtmlTag',array('tag' => 'dd', 'class' => 'ui-select span5'))));       


        $mgrp_desc = new Zend_Form_Element_Select('mgrp_desc');     
        $mgrp_desc  ->setLabel('Major Group')
                ->addMultiOption('--Select One--', '--Select One--');

        //$mdlMajorGroup = new Model_MajorGroup();
        //$majorgroups = $mdlMajorGroup->getmajorgroups();          
        //foreach ($majorgroups as $majorgroup)
        //{
            //$mgrp_desc->addMultiOption($majorgroup->mgrp_code, $majorgroup->mgrp_desc);
        //} 

        $mgrp_desc->addDecorator(array('row' => 'HtmlTag'), array('tag' => 'div','class' => 'col-md-12 field-box'))
             ->addDecorators(array(array('HtmlTag',array('tag' => 'dd', 'class' => 'ui-select span5'))));


        $grp_desc = new Zend_Form_Element_Select('grp_desc');       
        $grp_desc  ->setLabel('Group')
                ->addMultiOption('--Select One--', '--Select One--');

        //$mdlGroup = new Model_Group();
        //$groups = $mdlGroup->getgroups();         
        //foreach ($groups as $group)
        //{
            //$grp_desc->addMultiOption($group->grp_code, $group->grp_desc);
        //} 

        $grp_desc->addDecorator(array('row' => 'HtmlTag'), array('tag' => 'div','class' => 'col-md-12 field-box'))
             ->addDecorators(array(array('HtmlTag',array('tag' => 'dd', 'class' => 'ui-select span5')))); 


        $sic_description = new Zend_Form_Element_Select('sic_description');     
        $sic_description  ->setLabel('Sic Description')
                ->addMultiOption('--Select One--', '--Select One--');

        //$mdlSicCode = new Model_SicCode();
        //$siccodes = $mdlSicCode->getsiccodes();       
        //foreach ($siccodes as $siccode)
        //{
            //$sic_description->addMultiOption($siccode->id, $siccode->sic_description);
        //} 

        $sic_description->addDecorator(array('row' => 'HtmlTag'), array('tag' => 'div','class' => 'col-md-12 field-box'))
             ->addDecorators(array(array('HtmlTag',array('tag' => 'dd', 'class' => 'ui-select span5')))); 


        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('+Add');
        $submit->setAttrib('smmeid', 'submitbutton')
            ->setAttrib('class', 'btn-flat primary btn-next')
            ->setAttrib('style','float:left;')
            ->addDecorator(array('row' => 'HtmlTag'), array('tag' => 'div','class' => 'col-md-6 field-box','style' => 'width: 50%;'));

        $this->addElements(array($sector_name, $search, $div_desc, $mgrp_desc, $grp_desc, $sic_description, $description, $comments, $core_product, $submit));
}
}
这是一些照片 enter image description here
enter image description here

1 个答案:

答案 0 :(得分:0)

可能是Zend_Form的问题。 如果使用inArray Validator,则它不知道提供的值。尝试在字段上禁用它。

$field->setRegisterInArrayValidator(false);