本文整理汇总了PHP中Zend_Form::addSubForm方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form::addSubForm方法的具体用法?PHP Zend_Form::addSubForm怎么用?PHP Zend_Form::addSubForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Form
的用法示例。
在下文中一共展示了Zend_Form::addSubForm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
public function indexAction()
{
// action body
$idEncuesta = $this->getParam("idEncuesta");
$encuesta = $this->encuestaDAO->obtenerEncuesta($idEncuesta);
$secciones = $this->seccionDAO->obtenerSecciones($idEncuesta);
$formulario = new Zend_Form($encuesta->getHash());
//debemos agregar a este formulario campos para identificar quien es el que esta llenando esta encuesta
$eSubCabecera = new Zend_Form_SubForm();
$eSubCabecera->setLegend("Datos Personales: ");
$eEncuesta = new Zend_Form_Element_Hidden("idEncuesta");
$eEncuesta->setValue($idEncuesta);
$eReferencia = new Zend_Form_Element_Text("referencia");
$eReferencia->setLabel("Boleta o Clave : ");
$eReferencia->setAttrib("class", "form-control");
$eReferencia->setDecorators($this->decoratorsPregunta);
$eSubCabecera->addElements(array($eEncuesta, $eReferencia));
$eSubCabecera->setDecorators($this->decoratorsSeccion);
$formulario->addSubForm($eSubCabecera, "referencia");
//============================================= Iteramos a traves de las secciones del grupo
foreach ($secciones as $seccion) {
//============================================= Cada seccion es una subforma
$subFormSeccion = new Zend_Form_SubForm($seccion->getHash());
$subFormSeccion->setLegend("Sección: " . $seccion->getNombre());
//============================================= Obtenemos los elemntos de la seccion
$elementos = $this->seccionDAO->obtenerElementos($seccion->getIdSeccion());
foreach ($elementos as $elemento) {
//============================================= Verificamos que tipo de elemento es
if ($elemento instanceof Encuesta_Model_Pregunta) {
//============================================= Aqui ya la agregamos a la seccion
$this->agregarPregunta($subFormSeccion, $elemento);
} elseif ($elemento instanceof Encuesta_Model_Grupo) {
//============================================= un grupo es otra subform
$subFormGrupo = new Zend_Form_SubForm($elemento->getHash());
$subFormGrupo->setLegend("Grupo: " . $elemento->getNombre());
$preguntasGrupo = $this->grupoDAO->obtenerPreguntas($elemento->getIdGrupo());
foreach ($preguntasGrupo as $pregunta) {
//============================================= Aqui ya la agregamos al grupo
$this->agregarPregunta($subFormGrupo, $pregunta);
}
$subFormGrupo->setDecorators($this->decoratorsGrupo);
$subFormSeccion->addSubForm($subFormGrupo, $elemento->getIdGrupo());
}
}
$subFormSeccion->setDecorators($this->decoratorsSeccion);
$formulario->addSubForm($subFormSeccion, $seccion->getIdSeccion());
}
$eSubmit = new Zend_Form_Element_Submit("submit");
$eSubmit->setLabel("Enviar Encuesta");
$eSubmit->setAttrib("class", "btn btn-success");
$formulario->addElement($eSubmit);
$formulario->setDecorators($this->formDecorators);
$this->view->encuesta = $encuesta;
$this->view->formulario = $formulario;
}
示例2: testRenderedSubFormDtShouldContainNoBreakSpace
/**
* @see ZF-3272
*/
public function testRenderedSubFormDtShouldContainNoBreakSpace()
{
$subForm = new Zend_Form_SubForm(array('elements' => array('foo' => 'text', 'bar' => 'text')));
$form = new Zend_Form();
$form->addSubForm($subForm, 'foobar')->setView(new Zend_View());
$html = $form->render();
$this->assertContains('<dt> </dt>', $html);
}
示例3: testDisplayGroupsShouldInheritSubFormNamespace
/**
* @see ZF-2883
*/
public function testDisplayGroupsShouldInheritSubFormNamespace()
{
$this->form->addElement('text', 'foo')->addElement('text', 'bar')->addDisplayGroup(array('foo', 'bar'), 'foobar');
$form = new Zend_Form();
$form->addSubForm($this->form, 'attributes');
$html = $form->render(new Zend_View());
$this->assertContains('name="attributes[foo]"', $html);
$this->assertContains('name="attributes[bar]"', $html);
}
示例4: indexAction
/**
* Initiate system installation
*
*/
public function indexAction()
{
$settingsform = new Zoo_Form_Settings();
$modulesform = new Zoo_Form_Modules();
$form = new Zend_Form(array('name' => 'installForm'));
$form->setSubFormDecorators(array('FormElements', 'Fieldset'));
$form->addSubForm($settingsform, 'settings');
$form->addSubForm($modulesform, 'modules');
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($settingsform->isValid($formData)) {
// $this->_forward('install');
}
$form->populate($formData);
}
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Install');
$form->addElements(array($submit));
$this->view->form = $form;
}
示例5: testFormEnableShouldIncludeSubforms
public function testFormEnableShouldIncludeSubforms()
{
$form = new Zend_Form();
$subform = new Zend_Form();
$form->addSubForm($subform, "subform1");
$this->assertFalse(false !== $form->getPluginLoader('element')->getPaths('ZendX_JQuery_Form_Element'));
$this->assertFalse(false !== $form->getPluginLoader('decorator')->getPaths('ZendX_JQuery_Form_Decorator'));
ZendX_JQuery::enableForm($form);
$this->assertTrue(false !== $form->getPluginLoader('element')->getPaths('ZendX_JQuery_Form_Element'));
$this->assertTrue(false !== $form->getPluginLoader('decorator')->getPaths('ZendX_JQuery_Form_Decorator'));
}
示例6: testRenderTranslate
public function testRenderTranslate()
{
$this->useGerman();
$decorator = new Application_Form_Decorator_TableHeader();
$decorator->setColumns(array(array('label' => 'Value')));
$form = new Zend_Form();
$form->addSubForm(new Zend_Form_SubForm(), 'subform1');
$decorator->setElement($form);
$markup = $decorator->render('content');
$this->assertEquals('<thead><tr><th class="">Text</th></tr></thead>content', $markup);
}
示例7: testGetJumpLinks
public function testGetJumpLinks()
{
$testForm = new Zend_Form();
$subform = new Zend_Form_SubForm();
$subform->setLegend('Subform 1');
$testForm->addSubForm($subform, 'form1');
$subform = new Zend_Form_SubForm();
$subform->setLegend('Subform 2');
$testForm->addSubForm($subform, 'form2');
$subform = new Zend_Form_SubForm();
$subform->setLegend(null);
$testForm->addSubForm($subform, 'form3');
$form = new Admin_Form_ActionBox($testForm);
$links = $form->getJumpLinks();
$this->assertEquals(2, count($links));
$this->assertArrayHasKey('#fieldset-form1', $links);
$this->assertEquals('Subform 1', $links['#fieldset-form1']);
$this->assertArrayHasKey('#fieldset-form2', $links);
$this->assertEquals('Subform 2', $links['#fieldset-form2']);
}
示例8: initForm
/**
*/
public function initForm(Zend_Form $form, ListView $list, MemberView $member = null)
{
$newsletter = new Zend_Form_SubForm();
$newsletter->addElement('checkbox', 'subscriber', array('label' => 'I want to receive newsletter'));
foreach ($list->groups as $group) {
$type = $group['form_field'] == 'radio' ? 'radio' : 'multiCheckbox';
$newsletter->addElement($type, $group['name'], array('label' => $group['name'], 'multioptions' => $group['groups']));
}
if ($member !== null) {
$newsletter->setDefaults(array_merge((array) $member, $member->groups));
}
$form->addSubForm($newsletter, 'newsletter');
}
示例9: testGetValidSubFormValues
/**
* @group ZF-8494
*/
public function testGetValidSubFormValues()
{
$data = array('sub' => array('valid' => 1234, 'invalid' => 'invalid', 'noElement' => 'noElement'));
$subForm = new Zend_Form_SubForm();
$validElement = new Zend_Form_Element("valid");
$validElement->addValidator(new Zend_Validate_Int());
$subForm->addElement($validElement);
$invalidElement = new Zend_Form_Element('invalid');
$invalidElement->addValidator(new Zend_Validate_Int());
$subForm->addElement($invalidElement);
$this->form->addSubForm($subForm, 'sub');
$this->assertEquals(array('sub' => array('valid' => 1234)), $this->form->getValidValues($data));
}
示例10: testPrepareValidation
/**
* Jedem Language-Element in den Unterformularen wird ein Validator hinzugefügt. Formulare ohne Language-Element
* werden ignoriert.
*/
public function testPrepareValidation()
{
$form = new Zend_Form();
$titleCount = 3;
for ($index = 0; $index < $titleCount; $index++) {
$subform = new Zend_Form_SubForm();
$subform->addElement(new Application_Form_Element_Language('Language'));
$form->addSubForm($subform, 'Title' . $index);
}
$subform = new Zend_Form_Subform();
$subform->addElement('submit', 'Add');
$form->addSubForm($subform, 'Actions');
$instance = new Application_Form_Validate_MultiSubForm_RepeatedLanguages();
$post = array('Title0' => array('Id' => '1', 'Language' => 'deu', 'Value' => 'Titel 1'), 'Title1' => array('Id' => '2', 'Language' => 'fra', 'Value' => 'Titel 2'), 'Title2' => array('Id' => '3', 'Language' => 'rus', 'Value' => 'Titel 3'), 'Actions' => array('Add' => 'Add'));
$instance->prepareValidation($form, $post);
for ($index = 0; $index < $titleCount; $index++) {
$subform = $form->getSubForm('Title' . $index);
$validator = $subform->getElement('Language')->getValidator('Application_Form_Validate_LanguageUsedOnceOnly');
$this->assertNotNull($validator);
$this->assertEquals($index, $validator->getPosition());
$this->assertEquals(array('deu', 'fra', 'rus'), $validator->getLanguages());
}
}
示例11: testSubFormTranslatorPreferredOverDefaultTranslator
/**
* @group ZF-9540
*/
public function testSubFormTranslatorPreferredOverDefaultTranslator()
{
$defaultTranslations = array('isEmpty' => 'Default message');
$subformTranslations = array('isEmpty' => 'SubForm message');
$defaultTranslate = new Translator('ArrayAdapter', $defaultTranslations);
$subformTranslate = new Translator('ArrayAdapter', $subformTranslations);
Registry::set('Zend_Translator', $defaultTranslate);
$this->form->addSubForm(new SubForm(), 'subform');
$this->form->subform->setTranslator($subformTranslate);
$this->form->subform->addElement('text', 'foo', array('required' => true));
$this->assertFalse($this->form->isValid(array('subform' => array('foo' => ''))));
$messages = $this->form->getMessages();
$this->assertEquals('SubForm message', $messages['subform']['foo']['isEmpty']);
$this->assertFalse($this->form->isValidPartial(array('subform' => array('foo' => ''))));
$messages = $this->form->getMessages();
$this->assertEquals('SubForm message', $messages['subform']['foo']['isEmpty']);
}
示例12: editAction
public function editAction()
{
try {
$model = $this->getModel();
$dataForm = $this->getForm();
$form = new Zend_Form();
$form->addSubForm($dataForm, 'data');
$form->addElement('submit', $this->view->translate('Save'));
if ($this->_request->isPost()) {
$postData = $this->_request->getPost('data');
if ($dataForm->isValid($postData)) {
$this->view->messages = array();
$model->fromArray($postData);
$stored = $model->store();
if (!$stored) {
$dataForm->populate($postData);
$this->view->messages[] = array('level' => 'failure', 'message' => $this->view->translate('setup_message_write-failed'));
} else {
$this->view->messages[] = array('level' => 'notice', 'message' => $this->view->translate('setup_message_write-success'));
Zend_Translate::clearCache();
}
} else {
$this->view->messages[] = array('level' => 'failure', 'message' => 'Es ist ein Fehler aufgetreten. Bitte überprüfen Sie Ihre Eingaben.');
}
} else {
$formData = $model->toArray();
$dataForm->populate($formData);
}
$this->view->form = $form;
} catch (Setup_Model_FileNotReadableException $exc) {
$this->_redirectTo('error', array('failure' => $this->view->translate('setup_message_error_read-access', $exc->getMessage())));
} catch (Setup_Model_FileNotWriteableException $exc) {
$this->_redirectTo('error', array('failure' => $this->view->translate('setup_message_error_write-access', $exc->getMessage())));
} catch (Setup_Model_FileNotFoundException $exc) {
$this->_redirectTo('error', array('failure' => $this->view->translate('setup_message_error_filenotfound', $exc->getMessage())));
}
$this->render('edit', null, true);
}
示例13: testSubFormWithNumericName
/**
* @see ZF-11504
*/
public function testSubFormWithNumericName()
{
$subForm = new Zend_Form_SubForm(array('elements' => array('foo' => 'text', 'bar' => 'text')));
$form = new Zend_Form();
$form->addSubForm($subForm, 0);
$form->addSubForm($subForm, 234);
$form2 = clone $form;
$this->assertEquals($form2->getSubForm(234)->getName(), 234);
$this->assertEquals($form2->getSubForm(0)->getName(), 0);
}
示例14: reAssignElements
/**
* Explicitly removes and re-adds elements to the provided form to
* ensure that the form re-builds the element order.
*
* Due to a bug this is required if the order of an element is
* changed after the internal form index was created:
* {@link http://framework.zend.com/issues/browse/ZF-9946}
*
* @param Zend_Form $form
* @param array(Zend_Form_Element|Zend_Form|Zend_Form_DisplayGroup) $elements
*/
protected function reAssignElements(Zend_Form $form, array $elements)
{
$elementsByType = $this->categorizeElements($elements);
foreach ($elementsByType['elements'] as $element) {
/* @var $element Zend_Form_Element */
$form->removeElement($element->getName());
$form->addElement($element);
}
foreach ($elementsByType['subForms'] as $subForm) {
/* @var $subForm Zend_Form */
$form->removeSubForm($subForm->getName());
$form->addSubForm($subForm, $subForm->getName());
}
foreach ($elementsByType['displayGroups'] as $displayGroup) {
/* @var $displayGroup Zend_Form_DisplayGroup */
$form->removeDisplayGroup($displayGroup->getName());
$form->addDisplayGroup($displayGroup->getElements(), $displayGroup->getName());
}
}
示例15: addSubForm
/**
* Add a form group/subform
*
* @param Zend_Form $form
* @param string $name
* @param int $order
* @return Zend_Form
*/
public function addSubForm(Zend_Form $form, $name = null, $order = null)
{
if (!$name) {
$name = $form->getName();
}
$form->setParent($this);
return parent::addSubForm($form, $name, $order);
}