Esempio n. 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());
     }
 }
Esempio n. 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>';
Esempio n. 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');
 }
Esempio n. 4
0
 /**
  * Whether the form is valid.
  *
  * In this case, this checks whether the entire form is valid -- i.e. it
  * checks that all the steps are present if they contain required content,
  * and checks whether the form has been labelled as complete -- i.e. the
  * user is happy with all the data.
  *
  * @return bool  is valida and complete?
  */
 function isValid()
 {
     $valid = parent::isValid();
     if ($valid && $this->isPresent()) {
         // if the form is present, all steps with required content must
         // be present and valid...
         $steps = $this->steps;
         foreach ($steps as $s) {
             if (!$s->isValid()) {
                 $valid = false;
             }
         }
         // ... and the user must have marked this form as complete, i.e.
         // they are not still trying to edit it!
         if ($valid && !$this->is_complete) {
             $valid = false;
         }
     }
     return $valid;
 }