I'm fairly new with creating a web application and would like to seek help regarding dojo and zend framework. I'm having problems with validation on form submission and also need to create dynamic element when a button inside the form (add new moderator button) is clicked.
What I need is:- A dialog that pops up which includes the zend form.
- Form should have validation.
- Form should create dynamic text element when "new moderator" is clicked.
On form submission.
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.
- A form where I put validations on element creation.
- A view element that has a declarative dijit dialog where I "echoed" the zend form.
- A button that will fire and show the dijit dialog.
- A controller that validates form data and add form errors if any.
- Validation set on element creation is not being fired and shown in form.
- Where and how will I add the creation of new element when the "new moderator" button is clicked.
Here are my trimmed out code:
Formclass 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'
));
}
}
View
<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>
Controller
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');
}
I've seen some post with creating a dynamic element that uses ajax but it is not using a dijit dialog box on a form and mostly are in jquery where I also don't have any background.
I've already searched on the net but to no avail. Please help me out. Thanks in advance.