【发布时间】:2011-09-19 17:48:17
【问题描述】:
我对创建 Web 应用程序还很陌生,想寻求有关 dojo 和 zend 框架的帮助。我在验证表单提交时遇到问题,并且还需要在单击表单内的按钮(添加新版主按钮)时创建动态元素。
我需要的是:- 弹出一个对话框,其中包含 zend 表单。
- 表单应该有验证。
- 点击“新版主”时,表单应创建动态文本元素。
-
关于表单提交。
If an error occurs during validation show the errors on the popped up dialog and let user fix the error. On success redirect the user to the parent page that calls the popup dialog.
- 我对元素创建进行验证的表单。
- 具有声明性 dijit 对话框的视图元素,我在其中“回显” Zend 表单。
- 将触发并显示 dijit 对话框的按钮。
- 验证表单数据并添加表单错误(如果有)的控制器。
- 元素创建的验证集没有被触发并显示在表单中。
- 单击“新版主”按钮时,我将在何处以及如何添加新元素的创建。
这是我删减的代码:
形式class Form_Test
{
public $processed = false;
public function init()
{
parent::init();
$this->setAttribs(array('name'=>'test'));
$this->setAction('/myapp/new')->setMethod('
$this->addElement('ValidationTextBox', 'topic', array(
'label' => 'Topic: ',
'required' => true,
'trim' => true,
'validators' => array("alnum"),
'filters' => array(new Zend_Filter_StringToLower(),
new Zend_Filter_StringTrim()
)
)
);
$this->addElement('SimpleTextArea', 'desc', array(
'label' => 'Description: ',
'trim' => true
)
);
$this->addElement('ValidationTextBox', 'moderator', array(
'label' => 'Moderator: ',
'required' => true,
'trim' => true,
'validators' => array("EmailAddress"),
'filters' => array(new Zend_Filter_StringToLower(),
new Zend_Filter_StringTrim()
)
)
);
$this->addElement('SubmitButton', 'submit', array(
'label' => 'Create'
));
}
}
看法
<button class="myButton" type="button" onclick="dijit.byId('formDialog').show()">
New Topic
</button>
<div dojoType="dijit.Dialog" id="formDialog" title="Topic" style="width:500px; height:300px;">
<?php echo $this->form; ?>
</div>
控制器
public function newAction()
{
$form= new Form_Test();
$this->view->form = $form;
$form->submit->setLabel('Create');
$values = $form->getValues();
if( $this->_request->isPost())
{
if($form->isValid($_POST)){
$topic = new Application_Model_Topic();
$result = $topic->createNewTopic($_POST);
if($result == false){
$form->addError($result->error);
}
}
}
$this->view->form = $form;
// How to redirect to form if there's error?
$this->_redirect('/myapp/index');
}
我看过一些关于创建使用 ajax 的动态元素的帖子,但它没有在表单上使用 dijit 对话框,而且大部分是在 jquery 中,我也没有任何背景。
我已经在网上搜索过,但无济于事。请帮帮我。提前致谢。
【问题讨论】:
-
有人遇到与上述相同的情况并有答案吗?请帮助..我认为这可以通过 ajax 调用并在对话框中添加错误来完成,但我不知道如何在对话框表单上添加错误/新元素。一个例子将不胜感激。谢谢
标签: forms zend-framework validation dialog dojo