Beispiel #1
0
 /**
  * Prepare-filter forwards to get if form was present and valid.
  *
  * At this point, the request has not been sent, but has been created and is about to be.
  * If the request is valid, we want to skip out *before* the form is sent and simply
  * redirect.
  *
  * @param T_Response $response  encapsulated response to filter
  */
 protected function doPrepareFilter(T_Response $response)
 {
     if ($this->form->isPresent() && $this->form->isValid() && $this->forward) {
         // POST request is successful, therefore redirect to GET so the
         // back button cannot be used to repeat the request.
         $response->abort();
         throw new T_Response_Redirect($this->forward->getUrl());
     }
 }
Beispiel #2
0
$repeated->addChild(new T_Form_Text('company', 'Company'));
$start = new T_Form_Text('start', 'Start Date');
$start->setHelp('Enter date in format dd/mm/yyyy');
$start->setOptional()->attachFilter(new T_Validate_UnixDate('d|m|y'));
$repeated->addChild($start);
$fieldset->addChild($repeated);
$skills = new T_Form_TextArea('skills', 'Additional Info');
$skills->setOptional()->setHelp('Describe any additional career achievements, etc.');
$fieldset->addChild($skills);
$form->setForward($env->getRequestUrl());
// VALIDATE FORM
if ($env->isMethod('POST')) {
    $form->validate($env->input('POST'));
}
// ACTION FORM
if ($form->isPresent() && $form->isValid()) {
    $f = new T_Filter_Xhtml();
    // action (e.g. email, etc.)
    echo '<h2>CV for <a href="mailto:', $form->search('email')->getValue($f), '">', $form->search('name')->getValue($f), '</a></h2>';
    foreach ($form->search('jobs') as $job) {
        $date = $job->search('start');
        if ($date->isPresent()) {
            $date = ' (from ' . date('d-m-Y', $date->getValue()) . ')';
        } else {
            $date = null;
        }
        echo '<p>', $job->search('title')->getValue($f), ', ', $job->search('company')->getValue($f), $date, '</p>';
    }
    $skills = $form->search('skills');
    if ($skills->isPresent()) {
        echo '<p>', $skills->getValue($f), '</p>';
Beispiel #3
0
 function testFormIsInValidIfTimeStampExpires()
 {
     // GET
     $form = new T_Form_Post('test', 'label');
     $form->setForward(new T_Url('http', 'example.com'));
     $env = $this->getEnvironment('GET');
     $filter = new T_Form_PostHandler($form, $env, new T_Filter_RepeatableHash(), 'lock', -1);
     // tiemstamp of -1 means form has already run out!!
     $filter->preFilter($response = new T_Test_ResponseStub());
     // add checking inputs
     $filter->postFilter($response);
     $post = $this->getActionSaltTimeoutAndLockArray($form);
     // POST
     $form = new T_Form_Post('test', 'label');
     $form->setForward(new T_Url('http', 'example.com'));
     $env = $this->getEnvironment('POST', $post);
     $filter = new T_Form_PostHandler($form, $env, new T_Filter_RepeatableHash(), 'lock');
     $filter->preFilter($response = new T_Test_ResponseStub());
     $this->assertTrue($form->isPresent(), 'form is present');
     $this->assertFalse($form->isValid(), 'form is NOT valid');
 }
Beispiel #4
0
 /**
  * Whether any elements in form are present.
  *
  * @return bool
  */
 function isPresent()
 {
     $steps = $this->steps;
     // preserve internal array pointer
     foreach ($steps as $s) {
         if ($s->isPresent()) {
             return true;
         }
     }
     return parent::isPresent();
 }