TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 08-16-2009, 01:10 PM   #1 (permalink)
The Contributor
 
flyingbuddha's Avatar
 
Join Date: Jan 2008
Location: Birmingham, UK
Posts: 60
Thanks: 10
flyingbuddha is on a distinguished road
Default Help with decorator setup using Zend_Form

Hi all,

I'm trying to get my head around the Zend framework. One part I'm really getting stuck on is using the decorators with Zend_Form. I'm trying to add a couple of <div>'s before and after the main area but don't know how to - and the documentation is so hard to understand unless you know what you're looking for.

Here's what I'm trying to achieve:
HTML Code:
<form method="post" action="." enctype="multipart/form-data" accept-charset="utf8">
    <div class="head"></div>
    <div class="main">
        
        <div class="row cf">
            <label for="first_name">First Name:</label>
            <div class="w"><input type="text" name="first_name" id="first_name" title="First Name"  value="" class="text" /></div>
        </div>
        <div class="row cf">
            <label for="last_name">Last Name:</label>
            <div class="w"><input type="text" name="last_name" id="last_name" title="Last Name" value="" class="text" /></div>
        </div>
        <div class="row cf">
            <label for="email">Email:</label>
            <div class="w"><input type="text" name="email" id="email" title="Email" value="" class="text" /></div>
        </div>
        <div class="row cf">
            <label for="address">Address:</label>
            <div class="w"><textarea name="address" id="address" title="Address:" rows="5" cols="75"></textarea></div>
        </div>
        <div class="row cf">
            <label for="password">Password:</label>
            <div class="w"><input type="text" name="password" id="password" value="" class="text" autocomplete="off" /></div>
        </div>
        <div class="row cf">
            <label for="password_2">Confirm Password:</label>
            <div class="w"><input type="text" name="password_2" id="password_2" value="" class="text" /></div>
        </div>
    </div>
    <div class="foot">
        <input type="submit" value="Submit" class="button" />
    </div>
</form>
And this is what I have so far:
PHP Code:
<?php

    
class Default_Form_Register extends Zend_Form{
        
        public function 
init(){
            
            
// we don't want the default decorators
            
$this->setDisableLoadDefaultDecorators(true);
            
            
// set the form method
            
$this->setMethod('post');
            
            
// set the form decorator
            
$this->addDecorator('FormElements')
                ->
addDecorator('HtmlTag', array('tag' => 'div''class' => 'main'))
                ->
addDecorator('Form');

            
// set the element decorators
            
$this->setElementDecorators(array(
                
'ViewHelper',
                
'Label',
                
'Errors',
                new 
Zend_Form_Decorator_HtmlTag(array(
                    
'tag'   => 'div'
                    
'class' => 'row cf'
                
))
            ));
            
            
$this->addElement('text''first_name', array(
                
'label'         => 'First Name:',
                
'required'      => true,
                
'validators'    => array('NotEmpty')
            ));
            
$this->addElement('text''last_name', array(
                
'label'         => 'Last Name:',
                
'required'      => true,
                
'validators'    => array('NotEmpty')
            ));
            
$this->addElement('text''email', array(
                
'label'         => 'Email:',
                
'required'      => true,
                
'filters'       => array('StringTrim'),
                
'validators'    => array('EmailAddress')
            ));
            
$this->addElement('textarea''address', array(
                
'label'         => 'Address:',
                
'required'      => true,
                
'validators'    => array('NotEmpty')
            ));
            
$this->addElement('password''password', array(
                
'label'         => 'Password:',
                
'required'      => true,
                
'validators'    => array('NotEmpty')
            ));
            
// add CSRF protection
            
$this->addElement('hash''csrf', array(
                
'ignore' => true,
            ));
            
            
// Add the submit button
            
$this->addElement('submit''submit', array(
                
'ignore'        => true,
                
'label'         => 'Register',
            ));
            
            
// remove label from submit button
            
$this->submit->removeDecorator('Label');
        }
    }
Can someone whose a dab hand at using Zend help me fill in the blanks so that my html looks like what I'm after.

Cheers!
__________________
Pro. Geek
http://www.mikeholloway.co.uk
flyingbuddha is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:25 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design