jquery - zend/ajax 动态添加行的相关问题

标签 jquery mysql zend-framework

我有 3 个表,其中包含要选择的输入,第 4 个表将 3 个表的 id 作为该表内的外键,另外还有两列包含输入。这 4 个表相互依赖其他。我将它们与下拉菜单一起使用,例如选择大陆 dropwns 自动填充、国家/“省/州”/城市等,这也是存储此信息的第五个表。我想知道如何获取这些选定的变量并将它们保存在第五个表中。使用 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>

Action Controller ajax

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

最佳答案

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

$field->setRegisterInArrayValidator(false);

关于jquery - zend/ajax 动态添加行的相关问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21304163/

相关文章:

zend-framework - Zend 版本发布日期

jquery - css3 和 jquery 中的 rotateY 和宽度关系

javascript - 获取列表中随机生成的 li 的 id

mysql - SQL循环连接?

php - 需要有关变量 COUNT 查询的帮助

php - Zend 框架 : How do I change the default layout script to something other than layout. phtml?

javascript - 当鼠标离开 JQuery 时停止 .hover 动画

javascript - 将 URL 参数添加到 SPServices

mysql - 如果 且有计数,则选择总和

Mysql用多个where子句连接2个表