Patrioticcow
Patrioticcow

Reputation: 27038

how to, hidden field value not showing up on request in zend framework?

i have a simple form that has a textarea ans a hidden field

    $textarea = new Zend_Form_Element_Textarea('post');
    $textarea->setRequired(true);
    $textarea->setLabel('');

    $hidden = new Zend_Form_Element_Hidden('post_id');
    $hidden->setLabel('');
    $hidden->setValue('1');      

    $submit = new Zend_Form_Element_Submit('submit');
    $submit->setLabel('test');

    $this->addElement($textarea);
    $this->addElement($hidden);
    $this->addElement($submit);

    $this->setDecorators(array(
        'FormElements',
         array('HtmlTag', array('tag' => 'div', 'class' => 'form_class')),
        'Form'
    ));

in my view i do

<?php echo $this->form->getElement('post')->render(); ?>
<?php echo $this->form->getElement('submit')->render(); ?>

then in my controller

    $request = $this->getRequest();
    if( $request->isPost() && $form->isValid($request->getParams()))
    {
        Zend_Debug::dump($request->getParams());
    }

what happens is that i get

array(8) {
  ["module"] => string(6) "testr"
  ["controller"] => string(8) "posts"
  ["action"] => string(9) "post"
  ["post"] => string(10) "testgfdgfg"
  ["submit"] => string(26) "submit"
}

but no post_id

this is a bit wired and i cant figure it out. Ive looked for any code that might screw this up but nothing. I've also tried to echo the hidden field in the view, but i still get nothing on the request

any ideas?

thanks

Upvotes: 0

Views: 1391

Answers (2)

Amrish Prajapati
Amrish Prajapati

Reputation: 787

In View part you are just set two elements only

<?php echo $this->form->getElement('post')->render(); ?>
<?php echo $this->form->getElement('submit')->render(); ?>

WHERE form->getElement('post_id')->render(); ?>

 <?php echo $this->form->getElement('post')->render(); ?>
 <?php echo $this->form->getElement('submit')->render(); ?>
 <?php echo $this->form->getElement('post_id')->render(); ?>

Try once with this.

I think it will work.

Upvotes: 1

Mr Coder
Mr Coder

Reputation: 8186

In your view do

<?php echo $this->form->getElement('post'); ?>
<?php echo $this->form->getElement('post_id'); ?>
<?php echo $this->form->getElement('submit');?>

You are simply not echoing post_id element like you did with post and submit . Also you don't need to call render() since php magic function __toString() proxy render() in all Zend_Form_Element_XXX .

Upvotes: 3

Related Questions