views:

132

answers:

1

I'm pretty sure now that this cannot be done but I would appreciate clarification on why, so I can avoid similar situations in the future! I have a form that when submitted dependent on user input either completes or requires further input with a parameter needing to be passed to the new form.

The initial submit works fine and the values are accessed fine in the next form!

    $fooID = $foo->save($values);
    if($values['register'] == "true")
    {
      $this->_forward("register", "user", null, array('fooID' => $fooID));
    }else{
      $this->_redirect('/feedback/thanks');
    }

When I do the following in the action I am forwarding to, the correct ID is printed to the screen.

if($this->_getParam('fooID') != null){
    echo "FOO: ".$this->_getParam('fooID');
}

Yet for some reason I cannot either add an element to the $form initialised in this action nor can I populate the value of an existing field with any value.

$form->populate(array('fooID' => $this->_getParam('fooID')));

The above simply does nothing and the value isn't populated, for reference the element is instantiated like so:

     $this->addElement('hidden', 'fooID', array(
        'decorators' => $this->_noElementDecorator,
        'validators' => array(
            'Digits'
        ),
        'required' => true
    ));

What is weird though is that if I change fooID as the name of the hidden element, to just id, the value is populated with the url parameter of the previous form submission page.

As I said I know it can't be done, just wondering where the limitation lies if I can print the value side by side with the statement that doesn't populate the value of the element.

A: 
  • Is it possible that you are changing the value after your populate() executes? As an example: $form->isValid($this->_request->getPost()); will set new form values.

  • Try var_dump($form->fooID->getValue()); as a debugging line after populate(), and once before the action completes? What does that show you?

gnarf