Coincidentally, I was testing subforms on Monday.  Here is a somewhat
contrived login form created from two subforms.

I took a slightly different approach in that I wanted the form and subforms
created by config files and I am using a form viewscript to render the form. 

Code fragments below. Hope this helps.

- Steve W.

// 
        $config = new Zend_Config_Ini(APPLICATION_PATH .
'/config/forms.ini');
        $this->_loginForm   = new Zend_Form($config->login->login);
        
        $utilConfig = new Zend_Config_Ini(APPLICATION_PATH .
'/config/utilForms.ini');
        
        $this->_loginForm->addSubForm(new
Zend_Form_SubForm($utilConfig->util->login), 'login'); 
        $this->_loginForm->addSubForm(new
Zend_Form_SubForm($utilConfig->util->minimalInfo), 'minimalInfo');
        
        $element = new Zend_Form_Element_Submit('submit');
        $this->_loginForm->addElement($element, 'submit');
        
        $this->_loginForm->setDecorators( 
                                array( 
                                    array('ViewScript', array('viewScript'
=> 'login/login.phtml'))
                                )
        ); 

Here are my config files. Notice I am playing setting decorators.type to
ViewHelper to test the control  element decoration.

// forms.ini

;; Login Controller
;; Login Form
login.form = "login"
login.login.action = "identify"
login.login.method = "post"
;
login.login.elements.hidden.type = "hidden" 
login.login.elements.hidden.options.value = "testing"


// utilForms.ini

;; login subform
util.login.subform = true
util.login.subform.name = "_login"

; username element
util.login.elements.username.type = "text"
util.login.elements.username.options.validators.alnum.validator = "alnum"
util.login.elements.username.options.validators.regex.validator = "regex"
util.login.elements.username.options.validators.regex.options.pattern =
"/^[a-z]/i"
util.login.elements.username.options.validators.strlen.validator =
"StringLength"
util.login.elements.username.options.validators.strlen.options.min = "6"
util.login.elements.username.options.validators.strlen.options.max = "20"
util.login.elements.username.options.required = true
util.login.elements.username.options.filters.lower.filter = "StringToLower"
util.login.elements.username.options.label = "Username:"
util.login.elements.username.options.decorators.type = "ViewHelper"

; password element
util.login.elements.password.type = "password"
util.login.elements.password.options.validators.strlen.validator =
"StringLength"
util.login.elements.password.options.validators.strlen.options.min = "6"
util.login.elements.password.options.required = true
util.login.elements.password.options.label = "Password:"
util.login.elements.password.options.decorators.type = "ViewHelper"


;; minimualInfo subForm

util.minimalInfo.subform = true
util.minimalInfo.subform.name = "_minimalInfo"

; email element
util.minimalInfo.elements.email.type = "text"
util.minimalInfo.elements.email.options.validators.notempty.validator =
"NotEmpty"
util.minimalInfo.elements.email.options.validators.notempty.breakChainOnFailure
= true
util.minimalInfo.elements.email.options.validators.strlen.validator =
"StringLength"
util.minimalInfo.elements.email.options.validators.strlen.options.min = 1
util.minimalInfo.elements.email.options.validators.strlen.options.max = 50
util.minimalInfo.elements.email.options.required = true
util.minimalInfo.elements.email.options.label = "EMail:"

; phone element
util.minimalInfo.elements.phone.type = "text"
util.minimalInfo.elements.phone.options.validators.notempty.validator =
"NotEmpty"
util.minimalInfo.elements.phone.options.validators.notempty.breakChainOnFailure
= true
util.minimalInfo.elements.phone.options.validators.strlen.validator =
"StringLength"
util.minimalInfo.elements.phone.options.validators.strlen.options.min = 1
util.minimalInfo.elements.phone.options.validators.strlen.options.max = 15
util.minimalInfo.elements.phone.options.required = false
util.minimalInfo.elements.phone.options.label = "Phone:"

// Here is the ViewScript views/scripts/login/login.phtml

<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->actionMessages();?>
<p>Please log in here</p>
<form action="<?php echo $this->escape($this->loginForm->getAction()); ?>"
          method="<?php echo $this->escape($this->loginForm->getMethod());
?>">
    
    <div id="username" class="formLabel">Username:</div><?php echo
$this->loginForm->login->username; ?><br/>
    
    Password:<?php echo $this->loginForm->login->password; ?><br/>
    
    <?php echo $this->loginForm->minimalInfo->email; ?><br/>

    <?php echo $this->loginForm->minimalInfo->phone; ?><br/>

    <?echo $this->loginForm->submit ?>
</form>


qba_rox wrote:
> 
> HI
> I have one main form, and two sub forms, and I want to have a common
> submit button. But it really doesnt display that button after render
> action. 
> 
> got:
> 
> $this->setDecorators(array(
>                       'FormElements',         
>                   array('TabContainer', array(
>                       'id'          => 'newsTabs',
>                       'style'       => 'width: 960px;',
>                       'jQueryParams' => array()
>                   )),
>               'Form',
>               ));
> 
>               $submit = new Zend_Form_Element_Submit('submit');
>               $submit->setLabel('Save');
>               $this->addElement($submit);
> 
>               $this->addSubForm(new News_Form_General, 'general');
>               $this->addSubForm(new News_Form_Content, 'content');
> 
> and both sub forms are displayed, bot submit element is not. help :)
> 

-- 
View this message in context: 
http://www.nabble.com/zend-form%2C-sub-forms-and-submit-element-tp21460497p21461405.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to