2009-10-20 63 views
0

我有一個遠程窗體的contentPane,我試圖讓窗體提交,並保持在窗格內,不管是在錯誤還是報告成功時再次顯示窗體。 我確信這很容易,但我很難過,不是第一次,也不是最後一次。Zend_Dojo_Form onSubmit

存儲格式:

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

咆哮錯誤的樹。 在我的表單中帶有onclick事件的按鈕可以做到這一點。

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