/**
  * Class constructor
  *
  * Initializes a variable in $_SESSION array, its name is based upon the
  * name of the Controller passed here
  *
  * @param    HTML_QuickForm2_Controller
  */
 public function __construct(HTML_QuickForm2_Controller $controller)
 {
     $name = sprintf(HTML_QuickForm2_Controller::KEY_CONTAINER, $controller->getId());
     if (empty($_SESSION[$name])) {
         $_SESSION[$name] = array('datasources' => array(), 'values' => array(), 'valid' => array());
     }
     $this->data =& $_SESSION[$name];
 }
Beispiel #2
0
 public function __construct(HTML_QuickForm2_Controller $controller)
 {
     $this->name = sprintf(HTML_QuickForm2_Controller::KEY_CONTAINER, $controller->getId());
     /* @var $session Zend_Session_Namespace */
     if (empty($_SESSION['amember'][$this->name])) {
         $_SESSION['amember'][$this->name] = array('datasources' => array(), 'values' => array(), 'valid' => array());
     }
     $this->data =& $_SESSION['amember'][$this->name];
 }
 public function testNoValidationForWizards()
 {
     $mockForm = $this->getMock('HTML_QuickForm2', array('validate'), array('eternallyValid'));
     $mockForm->expects($this->once())->method('validate')->will($this->returnValue(true));
     $mockPage = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($mockForm));
     $mockPage->addHandler('jump', $this->getMock('HTML_QuickForm2_Controller_Action', array('perform')));
     $wizard = new HTML_QuickForm2_Controller('wizard', true);
     $wizard->addPage($mockPage);
     $mockPage->handle('back');
     $this->assertNull($wizard->getSessionContainer()->getValidationStatus('eternallyValid'));
     $nonWizard = new HTML_QuickForm2_Controller('nonWizard', false);
     $nonWizard->addPage($mockPage);
     $mockPage->handle('back');
     $this->assertTrue($nonWizard->getSessionContainer()->getValidationStatus('eternallyValid'));
 }
 function indexAction()
 {
     $controller = new HTML_QuickForm2_Controller('plugin_maker');
     $controller->addPage(new Am_Form_Controller_Page_PluginMaker_Mysql(new Am_Form('mysql')));
     $controller->addPage(new Am_Form_Controller_Page_PluginMaker_Plugin(new Am_Form('plugin')));
     $controller->addPage(new Am_Form_Controller_Page_PluginMaker_Tables(new Am_Form('tables')));
     $controller->addPage(new Am_Form_Controller_Page_PluginMaker_Columns(new Am_Form('columns')));
     $controller->addPage(new Am_Form_Controller_Page_PluginMaker_Display(new Am_Form('display')));
     $controller->addHandler('next', new HTML_QuickForm2_Controller_Action_Next());
     $controller->addHandler('back', new HTML_QuickForm2_Controller_Action_Back());
     $controller->addHandler('jump', new HTML_QuickForm2_Controller_Action_Jump());
     ob_start();
     $controller->run();
     $this->view->content = ob_get_clean();
     $this->view->title = "Integration Plugin Maker";
     $this->view->display('admin/layout.phtml');
 }
 public function testPerform()
 {
     $source = $this->getMock('HTML_QuickForm2', array('validate', 'getValue'), array('source'));
     $source->expects($this->once())->method('validate')->will($this->returnValue(true));
     $source->expects($this->once())->method('getValue')->will($this->returnValue(array('foo' => 'bar')));
     $sourcePage = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($source));
     $sourcePage->addHandler('destination', new HTML_QuickForm2_Controller_Action_Direct());
     $destPage = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array(new HTML_QuickForm2('destination')));
     $mockJump = $this->getMock('HTML_QuickForm2_Controller_Action', array('perform'));
     $mockJump->expects($this->once())->method('perform')->will($this->returnValue('jump to destination'));
     $destPage->addHandler('jump', $mockJump);
     $controller = new HTML_QuickForm2_Controller('testDirectAction');
     $controller->addPage($sourcePage);
     $controller->addPage($destPage);
     $this->assertEquals('jump to destination', $sourcePage->handle('destination'));
     $this->assertTrue($controller->getSessionContainer()->getValidationStatus('source'));
     $this->assertEquals(array('foo' => 'bar'), $controller->getSessionContainer()->getValues('source'));
 }
Beispiel #6
0
 /**
  * Wrapper around populateForm() ensuring that it is only called once
  */
 public final function populateFormOnce()
 {
     if (!$this->_formPopulated) {
         if (!empty($this->controller) && $this->controller->propagateId()) {
             $this->form->addElement('hidden', HTML_QuickForm2_Controller::KEY_ID, array('id' => HTML_QuickForm2_Controller::KEY_ID))->setValue($this->controller->getId());
         }
         $this->populateForm();
         $this->_formPopulated = true;
     }
 }
 public function testNoLoadFromSessionContainerOnOtherActions()
 {
     $mockForm = $this->getMock('HTML_QuickForm2', array('validate'), array('noload'));
     $foo = $mockForm->addElement('text', 'foo');
     $mockForm->expects($this->never())->method('validate');
     $mockPage = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($mockForm));
     $mockDisplay = $this->getMock('HTML_QuickForm2_Controller_Action_Display', array('renderForm'));
     $mockDisplay->expects($this->once())->method('renderForm')->will($this->returnValue('a form'));
     $mockPage->addHandler('display', $mockDisplay);
     $_REQUEST = array($mockPage->getButtonName('submit') => 'Yes, submit!');
     $controller = new HTML_QuickForm2_Controller('noLoadValues');
     $controller->addPage($mockPage);
     $controller->getSessionContainer()->storeValues('noload', array('foo' => 'bar'));
     $controller->getSessionContainer()->storeValidationStatus('noload', false);
     $controller->addDataSource(new HTML_QuickForm2_DataSource_Array(array('foo' => 'quux')));
     $this->assertEquals('a form', $mockPage->handle('display'));
     $this->assertEquals('quux', $foo->getValue());
 }
 public function testRedirectToInvalidPage()
 {
     $pageFirst = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array(new HTML_QuickForm2('first')));
     $formSecond = $this->getMock('HTML_QuickForm2', array('validate'), array('second'));
     $formSecond->expects($this->once())->method('validate')->will($this->returnValue(true));
     $pageSecond = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($formSecond));
     $mockJump = $this->getMock('HTML_QuickForm2_Controller_Action', array('perform'));
     $mockJump->expects($this->once())->method('perform')->will($this->returnValue('jump to first'));
     $pageFirst->addHandler('jump', $mockJump);
     $controller = new HTML_QuickForm2_Controller('redirect_invalid', false);
     $controller->addPage($pageFirst);
     $controller->addPage($pageSecond);
     $controller->getSessionContainer()->storeValidationStatus('first', false);
     $this->assertEquals('jump to first', $pageSecond->handle('submit'));
 }
 public function testPropagateControllerId()
 {
     $noPropPage = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array(new HTML_QuickForm2('noPropagateForm')));
     $noPropController = new HTML_QuickForm2_Controller('foo', true, false);
     $noPropController->addPage($noPropPage);
     $noPropPage->populateFormOnce();
     $hidden = $noPropPage->getForm()->getElementsByName(HTML_QuickForm2_Controller::KEY_ID);
     $this->assertEquals(0, count($hidden));
     $propPage = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array(new HTML_QuickForm2('propagateForm')));
     $propController = new HTML_QuickForm2_Controller('bar', true, true);
     $propController->addPage($propPage);
     $propPage->populateFormOnce();
     $hidden = $propPage->getForm()->getElementsByName(HTML_QuickForm2_Controller::KEY_ID);
     $this->assertNotEquals(0, count($hidden));
     $this->assertEquals('bar', $hidden[0]->getValue());
 }
 /**
  * Default values for checkboxes and multiselects were ignored when validating an unseen page
  *
  * Unlikely that this bug will resurface, but just in case.
  *
  * @see http://pear.php.net/bugs/bug.php?id=8687
  */
 public function testBug8687()
 {
     $mockForm = $this->getMock('HTML_QuickForm2', array('validate'), array('invalid'));
     $mockForm->expects($this->once())->method('validate')->will($this->returnValue(false));
     $select = $mockForm->addElement('select', 'foo', array('multiple'))->loadOptions(array('one' => 'First label', 'two' => 'Second label'));
     $box = $mockForm->addElement('checkbox', 'bar');
     $mockPage = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($mockForm));
     $controller = new HTML_QuickForm2_Controller('bug8687', false);
     $controller->addPage($mockPage);
     $controller->addDataSource(new HTML_QuickForm2_DataSource_Array(array('foo' => array('two'), 'bar' => '1')));
     $this->assertFalse($controller->isValid());
     $this->assertEquals(array('two'), $select->getValue());
     $this->assertEquals('1', $box->getValue());
 }
    width: 560px;
}

/* Use default styles included with the package */

<?php 
        if ('@data_dir@' != '@' . 'data_dir@') {
            $filename = '@data_dir@/HTML_QuickForm2/quickform.css';
        } else {
            $filename = dirname(dirname(dirname(__FILE__))) . '/data/quickform.css';
        }
        readfile($filename);
        ?>
    </style>
    <title>HTML_QuickForm2 simple controller example</title>
  </head>
  <body>
<?php 
        echo $form;
        ?>
  </body>
</html>
<?php 
    }
}
$page = new SimplePage(new HTML_QuickForm2('page1'));
$page->addHandler('process', new SimpleProcess());
$page->addHandler('display', new SimpleDisplay());
$controller = new HTML_QuickForm2_Controller('Simple');
$controller->addPage($page);
$controller->run();
        ?>
  </body>
</html>
<?php 
    }
}
class TabbedProcess implements HTML_QuickForm2_Controller_Action
{
    public function perform(HTML_QuickForm2_Controller_Page $page, $name)
    {
        echo "Submit successful!<br>\n<pre>\n";
        var_dump($page->getController()->getValue());
        echo "\n</pre>\n";
    }
}
$tabbed = new HTML_QuickForm2_Controller('Tabbed', false);
$tabbed->addPage(new PageFoo(new HTML_QuickForm2('foo')));
$tabbed->addPage(new PageBar(new HTML_QuickForm2('bar')));
$tabbed->addPage(new PageBaz(new HTML_QuickForm2('baz')));
// These actions manage going directly to the pages with the same name
$tabbed->addHandler('foo', new HTML_QuickForm2_Controller_Action_Direct());
$tabbed->addHandler('bar', new HTML_QuickForm2_Controller_Action_Direct());
$tabbed->addHandler('baz', new HTML_QuickForm2_Controller_Action_Direct());
// We actually add these handlers here for the sake of example
// They can be automatically loaded and added by the controller
$tabbed->addHandler('submit', new HTML_QuickForm2_Controller_Action_Submit());
$tabbed->addHandler('jump', new HTML_QuickForm2_Controller_Action_Jump());
// This is the action we should always define ourselves
$tabbed->addHandler('process', new TabbedProcess());
// We redefine 'display' handler to use the proper stylesheets
$tabbed->addHandler('display', new TabbedDisplay());
        $renderer->setTemplateForId('nameGrp', '<div class="row"><p class="label"><qf:required><span class="required">*</span></qf:required><qf:label><label>{label}</label></qf:label></p>{content}</div>');
        echo $form->render($renderer);
        ?>
  </body>
</html>
<?php 
    }
}
class WizardProcess implements HTML_QuickForm2_Controller_Action
{
    public function perform(HTML_QuickForm2_Controller_Page $page, $name)
    {
        echo "Submit successful!<br>\n<pre>\n";
        var_dump($page->getController()->getValue());
        echo "\n</pre>\n";
    }
}
$wizard = new HTML_QuickForm2_Controller('Wizard');
$wizard->addPage(new PageFirst(new HTML_QuickForm2('page1')));
$wizard->addPage(new PageSecond(new HTML_QuickForm2('page2')));
$wizard->addPage(new PageThird(new HTML_QuickForm2('page3')));
// We actually add these handlers here for the sake of example
// They can be automatically loaded and added by the controller
$wizard->addHandler('next', new HTML_QuickForm2_Controller_Action_Next());
$wizard->addHandler('back', new HTML_QuickForm2_Controller_Action_Back());
$wizard->addHandler('jump', new HTML_QuickForm2_Controller_Action_Jump());
// This is the action we should always define ourselves
$wizard->addHandler('process', new WizardProcess());
// We redefine 'display' handler to use the proper stylesheets
$wizard->addHandler('display', new WizardDisplay());
$wizard->run();
 public function testNonWizardBehaviour()
 {
     $formOne = $this->getMock('HTML_QuickForm2', array('validate'), array('one'));
     $formOne->expects($this->exactly(2))->method('validate')->will($this->onConsecutiveCalls(false, true));
     $formTwo = $this->getMock('HTML_QuickForm2', array('validate'), array('two'));
     $formTwo->expects($this->exactly(2))->method('validate')->will($this->onConsecutiveCalls(false, true));
     $mockJumpTwo = $this->getMock('HTML_QuickForm2_Controller_Action', array('perform'));
     $mockJumpTwo->expects($this->any())->method('perform')->will($this->returnValue('jump to page two'));
     $mockDisplay = $this->getMock('HTML_QuickForm2_Controller_Action', array('perform'));
     $mockDisplay->expects($this->any())->method('perform')->will($this->returnValue('output form'));
     $pageOne = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($formOne));
     $pageTwo = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($formTwo));
     $pageTwo->addHandler('jump', $mockJumpTwo);
     $pageTwo->addHandler('display', $mockDisplay);
     $controller = new HTML_QuickForm2_Controller('nonwizard_next', false);
     $controller->addPage($pageOne);
     $controller->addPage($pageTwo);
     // Don't bother whether the page is valid
     $this->assertEquals('jump to page two', $pageOne->handle('next'));
     $this->assertEquals('jump to page two', $pageOne->handle('next'));
     // Non-wizard form requires an explicit submit
     $this->assertEquals('output form', $pageTwo->handle('next'));
     $this->assertEquals('output form', $pageTwo->handle('next'));
 }
 public function testHttpXForwardedHost()
 {
     $_SERVER['HTTP_X_FORWARDED_HOST'] = 'example.org, example.com';
     $_SERVER['HTTP_HOST'] = 'localhost';
     $controller = new HTML_QuickForm2_Controller('forwarded');
     $mockPage = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array(new HTML_QuickForm2('forwarded')));
     $controller->addPage($mockPage);
     $controller->addHandler('jump', $this->mockJump);
     $mockPage->getForm()->setAttribute('action', '/foo');
     $this->assertStringStartsWith('http://localhost/foo?', $mockPage->handle('jump'));
     $trustingJump = $this->getMock('HTML_QuickForm2_Controller_Action_Jump', array('doRedirect'), array(true));
     $trustingJump->expects($this->atLeastOnce())->method('doRedirect')->will($this->returnArgument(0));
     $controller->addHandler('jump', $trustingJump);
     $this->assertStringStartsWith('http://example.com/foo?', $mockPage->handle('jump'));
 }