append Zend Form display group name into element's name

Discussion in 'PHP' started by thesafeone, Dec 9, 2010.

  1. #1
    I want to append group's name into element's name the same way sub form appends its name. If I add a subform named 'basicDetails' and add a text field 'firstName' into the sub form the code will be something

    <input type="text" value="" id="basicDetails-firstName" name="basicDetails[firstName]" />
    Code (markup):
    I want to achieve the same with groups so if I add a group 'personalInformation' in the subform and add the 'firstName' element into this group, ZF generate

    <input type="text" value="" id="basicDetails-personalInformation-firstName" name="basicDetails[personalInformation][firstName]" />
    
    Code (markup):
    any suggestions
     
    thesafeone, Dec 9, 2010 IP
  2. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #2
    Why not generate another subform instead of a group, since they both use fieldset decorator and Zend supports nested subforms?
    
    $form = new Zend_Form();
    $form->addElement('Text','username');
    $sForm = new Zend_Form_SubForm();
    $sForm->addElement('Text','email');
    $form->addSubForm($sForm, 'basicDetails');
    
    $ssForm = new Zend_Form_SubForm();
    $ssForm->addElement('Text','firstName');
    $sForm->addSubForm($ssForm, 'personalInformation');
    
    echo $form->render();
    
    PHP:
     
    Gray Fox, Dec 9, 2010 IP