Example #1
0
 /**
  * Visit a hidden input.
  *
  * @param T_Form_Hidden
  */
 function visitFormHidden(T_Form_Hidden $node)
 {
     $this->data[$node->getFieldname()] = $node->getFieldValue();
     $this->data[$node->getChecksumFieldname()] = $node->getChecksumFieldValue();
 }
Example #2
0
 /**
  * Visit a hidden input node.
  *
  * @param T_Form_Hidden $node
  */
 function visitFormHidden(T_Form_Hidden $node)
 {
     $xhtml = $this->indent . '<div class="hidden">' . EOL;
     // render value
     $attributes = $node->getAllAttributes();
     $attributes += array('type' => 'hidden', 'name' => $node->getFieldname(), 'value' => $node->getFieldValue());
     $xhtml .= $this->indent . '<input ';
     foreach ($attributes as $key => $value) {
         $xhtml .= $key . '="' . $this->escape($value) . '"' . EOL . $this->indent . '       ';
     }
     $xhtml = rtrim($xhtml) . ' /> ' . EOL;
     // render checksum
     $attributes = array('type' => 'hidden', 'name' => $node->getChecksumFieldname(), 'value' => $node->getChecksumFieldValue());
     $xhtml .= $this->indent . '<input ';
     foreach ($attributes as $key => $value) {
         $xhtml .= $key . '="' . $this->escape($value) . '"' . EOL . $this->indent . '       ';
     }
     $xhtml = rtrim($xhtml) . ' /> ' . EOL;
     $xhtml .= $this->indent . '</div>' . EOL;
     $this->addXhtml($xhtml);
 }
Example #3
0
 /**
  * Pre-filter actions any submission, or prepares the form.
  *
  * @param T_Response $response  encapsulated response to filter
  */
 protected function doPreFilter(T_Response $response)
 {
     $t_field = $this->form->getAlias() . '_timeout';
     $l_field = $this->form->getAlias() . '_thread_lock';
     $s_field = $this->form->getAlias() . '_salt';
     // prepare form:
     //   (a) add thread lock if required
     //   (b) add timeout
     $timeout = new T_Form_Hidden($t_field, $this->timeout + time());
     $this->form->addChild($timeout);
     if ($this->lock_to) {
         $lock_to = new T_Form_Hidden($l_field, $this->lock_to);
         $this->form->addChild($lock_to);
     }
     // process form if is POST:
     if ($this->env->isMethod('POST')) {
         try {
             // create salt field and validate to get salt
             $salt = new T_Form_Hidden($s_field, null);
             if ($salt->isSubmitted($this->env->input('POST'))) {
                 $salt->validate($this->env->input('POST'));
             }
             // salt form and validate
             if ($salt->isPresent() && $salt->isValid()) {
                 $salt = $salt->getValue();
                 $this->form->setFieldnameSalt($salt, $this->hash);
                 if ($this->form->isSubmitted($this->env->input('POST'))) {
                     $this->form->validate($this->env->input('POST'));
                 }
             }
             // check timeout and thread lock
             if ($this->form->isPresent() && $this->form->isValid()) {
                 // check timeout
                 $timeout = $this->form->search($t_field)->getValue();
                 if ($timeout < time()) {
                     $msg = 'This form has expired. Please submit the form ' . 'again to complete your request.';
                     throw new T_Exception_Filter($msg);
                 }
                 // check lock thread
                 if ($this->lock_to) {
                     $lock_to = $this->form->search($l_field)->getValue();
                     if (strcmp($lock_to, $this->lock_to) !== 0) {
                         $msg = 'A technical error occurred at our end, sorry. ' . 'Please submit the form again.';
                         throw new T_Exception_Filter($msg);
                     }
                 }
             }
         } catch (T_Exception_Filter $e) {
             $this->form->setError(new T_Form_Error($e->getMessage()));
         }
     }
     // ready form for redisplay (remember an error may be added in the POST
     // method so make even a valid form ready for display).
     //   (a) Set form forward as same page
     //   (b) Salt form and add salt hidden input
     //   (c) Reset timeout from now
     $this->form->setForward($this->env->getRequestUrl()->setParameters($this->env->input('GET')->uncage()));
     $salt = uniqid(rand(), true);
     $this->form->setFieldnameSalt($salt, $this->hash);
     $this->form->addChild(new T_Form_Hidden($s_field, $salt));
     // note that the salt hidden input is added *after* the form is
     // salted as this input needs to be plain.
     $this->form->search($t_field)->setValue($this->timeout + time());
 }
Example #4
0
 function testGetAttributeReturnsNullIfNameNotSet()
 {
     $input = new T_Form_Hidden('alias', 'value');
     $this->assertSame($input->getAttribute('name'), null);
 }
Example #5
0
 /**
  * Initialise the form to display the current step.
  *
  * @return void
  */
 protected function init()
 {
     $cur = current($this->steps);
     if (!$cur) {
         return;
     }
     // parse prev/next steps
     $steps = $this->steps;
     $prev = false;
     $next = false;
     $found = false;
     foreach ($steps as $s) {
         if (!$found && $s === $cur) {
             $found = true;
             continue;
         }
         if (!$found) {
             $prev = $s;
         }
         if ($found && false == $next) {
             $next = $s;
         }
     }
     // setup forward label
     if ($next) {
         $label = 'Next: ' . $next->getLabel();
     } else {
         $label = $this->getLabel();
     }
     if (isset($this->action['forward'])) {
         $this->action['forward']->setLabel($label);
     } else {
         $forward = new T_Form_Button('forward', $label);
         $this->addAction($forward);
     }
     // *always* setup prev action (needed to detect prev actions)
     //
     // NB: The prev action is always setup and validated internally. It
     //     is hidden in external getActions() calls by the is_prev_action
     //     flag. This is necessary to detect prev action when a salted form
     //     is validated.
     if ($this->is_prev_action = (bool) $prev) {
         $label = 'Back to ' . $prev->getLabel();
     } else {
         $label = 'Back';
     }
     if (isset($this->action['prev'])) {
         $this->action['prev']->setLabel($label);
     } else {
         $back = new T_Form_Button('prev', $label);
         $this->addAction($back);
     }
     // save history for other form steps form
     $data = new T_Form_Export();
     $child = $this->steps;
     // leave original pointer intact
     foreach ($child as $f) {
         if ($f === $cur) {
             continue;
         }
         if ($f->isPresent()) {
             $f->accept($data);
         }
     }
     if ($history = $this->search('history')) {
         $history->setValue($data->getData());
     } else {
         $field = new T_Form_Hidden('history', $data->getData());
         $field->attachFilter(new T_Filter_ToUrlQuery());
         $this->addChild($field);
     }
     // set current seek point
     if ($seek = $this->search('seek')) {
         $seek->setValue(key($this->steps));
     } else {
         $field = new T_Form_Hidden('seek', key($this->steps));
         $this->addChild($field);
     }
 }