NYCPHP Meetup

NYPHP.org

[nycphp-talk] HTML_QuickForm_Controller

Jayesh Sheth jayeshsh at ceruleansky.com
Thu Sep 23 14:15:11 EDT 2004


Hi David and others,

I tried David's advice (exportValue() method), and it worked after some 
experimentation. I thought I would post what I found out here to save 
others some time.

Suppose you you define a test element in the first page:

class Page_One extends HTML_QuickForm_Page
{

    function buildForm()
    {
      $testelement1 =& HTML_QuickForm::createElement('text', 
'testelement1', 'Test Element 1:');
      $this->addElement($testelement1);

     /*
      OR:
     $this->addElement('text', 'testelement1', 'Test Element 1:');
     */
    }
}

Then you define the second page:

class Page_Two extends HTML_QuickForm_Page
{

    function buildForm()
    {
     $expval1 = $this->controller->exportValue('page1', 'testelement1');
    $this->addElement('header', 'test_header1', "Test value from 
previous screen: $expval1 ");
    }
}

The point to note above is the "$this->controller->exportValue()" syntax.
I am guessing that due to the subclassing and stuff you have to do the 
weird looking  double -> thing.

Another point to note is that I don't think that in the code block for 
page two you could do something like:

$testelement1 =& $this->getElement('testelement1');
$expval1 = $testelement1->getValue();

Further examples of this technique can be found  on  line 62 of 
"upload.php" which is in the examples folder of the QuickForm Controller 
package.

An excerpt:
"
if ($this->controller->exportValue('page1', 'layout') == 'A')
      {
            $this->addGroup(array($upped, $text), 'contents', 'Enter the 
contents', null, false);
        }
else {
            $this->addGroup(array($text, $upped), 'contents', 'Enter the 
contents', null, false);       
        }
"

Finally, the an excerpt from the Controller.php source:

/**
    * Returns the element's value
    *
    * @access public
    * @param  string    name of the page
    * @param  string    name of the element in the page
    * @return mixed     value for the element
    */
    function exportValue($pageName, $elementName)
    {
        $data =& $this->container();
        return isset($data['values'][$pageName][$elementName])? 
$data['values'][$pageName][$elementName]: null;
    }

- Jay
PS: Does anyone know how to (using QuickForm) add an explanatory block 
of information (other than by adding a "header") next to a certain 
element in a form?



More information about the talk mailing list