Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-15-2008, 05:22 PM
Junior Member
 
Join Date: May 2008
Posts: 1
Default zend forms w view script

Decorators with Zend_Form

just turned to zend framework recently. im java programmer, who code php + zend in my spare time.

The article describe how to add decorators to a zend form. Im one of those who don't like the default - cause im trying to port my existing homepage, and ... css is time consuming.

but it also describes how to use view script with zend forms - gives you 100% control. Nice - lets begin.

Made a login form - its a rip off from a tutorial, but this is how I used quickform from pear also, so its kinda familiar.
LoginForm.php
PHP Code:
class LoginForm extends Zend_Form
{
    public function 
__construct($options null)
    {
        
                            
        
parent::__construct($options);
        
$this->setName('loginForm');

        
$username = new Zend_Form_Element_Text('username');
        
$username->setLabel('Username')
        ->
setRequired(true)
        ->
addFilter('StripTags')
        ->
addFilter('StringTrim')
        ->
addValidator('NotEmpty');
        
        
$password = new Zend_Form_Element_Text('password');
        
$password->setLabel('Password')
        ->
setRequired(true)
        ->
addFilter('StripTags')
        ->
addFilter('StringTrim')
        ->
addValidator('NotEmpty');
        
        
$id = new Zend_Form_Element_Hidden('id');
        
        
$submit = new Zend_Form_Element_Submit('submit');
        
$submit->setAttrib('id''submitbutton');
                
        
$this->setDecorators( array( array('ViewScript', array('script' => 'loginForm.phtml'))));
        

        
$this->addElements(array($id$username$password$submit));
    }

setDecorators( array( array('ViewScript', array('script' => 'loginForm.phtml'))));
This confuses me, cause I haven't managed to understand what Im doing here, and what parameters I set.

setDecorators, removes all existing decorators, and takes an array of decorators ... and I specify it is an ViewScript .. ok ... script is for??? and the form ofc ...

But i get an exception error, saying: Warning: No view script registered with ViewScript decorator in C:\www\webroot\zftutorial150\library\Zend\Form.php on line 2179

I have a feeling that the form has to know the path to the viewscript ... or ...
Im kinda confused cause alot seems to work without any configuration, if not you got to configure stuff ... but how and when ...
Reference doc is confusing, api doc is microscopic

My view script...
loginForm.phtml
PHP Code:
<form action="<?= $this->escape($this->login->getAction() ?>"
      method="<?= $this->escape($this->login->getMethod() ?>">
<?= $this->login->id ?>
Username<br />
<?= $this->login->username ?><br />
Password<br />
<?= $this->login->password ?><br />
    


<?= $this->login->submit ?>

</form>
part of IndexController.php
PHP Code:
class IndexController extends Zend_Controller_Action 
{
    function 
indexAction()
    {
        
$this->view->title "My Albums";
                
$albums = new Albums();
        
$this->view->albums $albums->fetchAll();
        
        
$loginForm = new LoginForm();
        
$loginForm->submit->setLabel'Login' );
        
$this->view->loginForm $loginForm;
    }

I have a layout file where I just do this: <?php echo $this->loginForm; ?> .. and standard zend form works splendid right away ... but when I tried to make it use a viewscript it does not work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-08-2008, 10:29 PM
Junior Member
 
Join Date: Jul 2008
Posts: 1
Default Same issue

I'm having the same issue but I have yet to see it explained anywhere.

The only difference in my code is that in the .phtml I use "form" instead of "login" as suggested by the tutorials.

PHP Code:
<?= $this->form->submit ?>
However when I run this code I get errors because "form" is not an object. I have dumped the contents of "$this" to the screen from the custom view script and I can see all of the correct data and elements but I do not see the correct way to reference them. Has anyone successfully corrected this error?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-31-2008, 05:46 PM
Junior Member
 
Join Date: Jul 2008
Posts: 2
Default script should be viewScript

Hi folks,

I had the same problem and it is a little tricky to spot: 'script' has to be 'viewScript'.

PHP Code:
$this->setDecorators( array( array('ViewScript', array('script' => 'loginForm.phtml')))); 
to

PHP Code:
$this->setDecorators( array( array('ViewScript', array('viewScript' => 'loginForm.phtml')))); 
I found this in the Zend documentation: 17.7.12. Zend_Form_Decorator_ViewScript here:

Zend Framework: Documentation

Hope this helps!
Valdeva
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-01-2008, 01:30 PM
Junior Member
 
Join Date: Jul 2008
Posts: 2
Default

One other thing - it should be

PHP Code:
$this->element->submit 
I found that in the comments in the link I posted above. 'form' is in the examples but it is incorrect.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-21-2008, 03:10 PM
Junior Member
 
Join Date: Jul 2008
Posts: 8
Default

I've been having problems with this also, the viewscript doesn't crash out and I can get the getAction() and getMethod() functions when in the script.

However the elements of my form do not render. I use the following code:

PHP Code:
<?php $this->element->email ?>
The page is rendered fine with all the static html and alike however the email text box does not render.

Here is the element within my Form code:

PHP Code:
$email = new Zend_Form_Element_Text('email');
        
$email->setRequired(true)
            ->
addFilter('StripTags')
            ->
addFilter('StringTrim')
            ->
addFilter('StringToLower')
            ->
addValidator('NotEmpty')
            ->
addValidator('EmailAddress')
            ->
setAttrib('class''textinput_blue'); 
Any ideas on why this would be the case as this is driving me mad.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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 05:19 AM.