
Jeremy Kendall
By: a guest on Jan 21st, 2009 | syntax:
PHP | size: 1.48 KB | hits: 2,579 | expires: Never
<?php
/**
* FormsController
*
* @author Jeremy Kendall <jeremy@jeremykendall.net>
*/
require_once 'Zend/Controller/Action.php';
class FormsController extends Zend_Controller_Action {
/**
* The default action - show the home page
*/
public function indexAction() {
// TODO Auto-generated FormsController::indexAction() default action
}
/**
* Shows the dynamic form demonstration page
*/
public function dynamicFormElementsAction() {
$form = new Code_Form_Dynamic();
// Form has not been submitted - pass to view and return
if (!$this->getRequest()->isPost()) {
$this->view->form = $form;
return;
}
// Form has been submitted - run data through preValidation()
$form->preValidation($_POST);
// If the form doesn't validate, pass to view and return
if (!$form->isValid($_POST)) {
$this->view->form = $form;
return;
}
// Form is valid
$this->view->form = $form;
}
/**
* Ajax action that returns the dynamic form field
*/
public function newfieldAction() {
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('newfield', 'html')->initContext();
$id = $this->_getParam('id', null);
$element = new Zend_Form_Element_Text("newName$id");
$element->setRequired(true)->setLabel('Name');
$this->view->field = $element->__toString();
}
}