代码之家  ›  专栏  ›  技术社区  ›  piddl0r

提交Zend-Dojo表格

  •  0
  • piddl0r  · 技术社区  · 15 年前

    我有一个带有远程表单的ContentPane,我正在尝试让表单提交,并保持在该窗格中,或者在出错时再次显示表单,或者报告成功。 我相信这很容易,但我被难住了,不是第一次,也不是最后一次。

    商店形式:

        class Services_Form_Store extends Zend_Dojo_Form {
        protected $_actionUrl;
        public function __construct($actionUrl = null, $options=null)
        {
            parent::__construct($options);
            $this->setActionUrl($actionUrl);
            $this->init();
        }
    
        public function setActionUrl($actionUrl) {
            $this->_actionUrl = $actionUrl;
            return $this;
        }
    
        public function init()
        {
            $required = true;
    
            $this->setMethod('post')
                 ->setAttrib('id', 'storeform')
                 ->setAttrib('name', 'storeform')
                 ->setAttrib('onSubmit', 'dojo.xhrGet(sub) return false;');
    
             $this->addElement('TextBox', 'location', array(
                'label'       => 'Location name :',
        'required'  => true,
                'trim'        => true,
                'propercase'  => true)
            );
    
            $submit = new Zend_Form_Element_Submit('submit');
      $submit->setLabel('save');
      $this->addElement($submit);
        }
    }
    

    我的看法是:

        <script type="dojo/method" event="onSubmit">
     var sub = {
      url : "/storemamager/new",
      load : function(data){
       dojo.byId('storeform').value = data;
      },
      error : function(data){
       console.debug("error submitting data :" + data);
      },
      timeout : 2000,
      form : "storeform"
     }
        </script>
        <?php echo(empty($this->formResponse) ? '' : '<p class="errors">' . $this->formResponse . '</p>'); ?>
        <?php echo $this->form; ?>
    

    这一切都是新的,所以很抱歉线路与WTF的比率。

    编辑:代码混乱

    1 回复  |  直到 15 年前
        1
  •  1
  •   piddl0r    15 年前

    找错树了。 在我的表单中,一个带有onclick事件的按钮就可以实现这一点。

    $this->addElement('Button', 'submit', array(
            'label'     =>  'Save',
            'onclick'   =>  'dojo.xhrPost(
                                {
                                    url : "url",
                                    timeout : 2000,
                                    form : "form"
                                }
                            );'