function testMimeIsMultipartWhenVisitsFormWithFileUpload() { $mime = new T_Form_Mime(); $form = new T_Form_Post('alias', 'label'); $form->addChild(new T_Form_Text('child', 'label')); $form->addChild(new T_Form_Upload('file', 'label')); $form->accept($mime); $this->assertSame('multipart/form-data', $mime->__toString()); }
/** * 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()); } }
.text($repeat.attr('title')) .click(function(){ $('li.group:hidden:first',$repeat).show(); if ($('li.group:hidden',$repeat).length==0) $(this).remove(); return false; }) ); } }); }); // ]]> </script> <?php // CREATE FORM $form = new T_Form_Post('cv', 'Create CV'); $fieldset = new T_Form_Fieldset('details', 'Your Details'); $form->addChild($fieldset); $fieldset->addChild(new T_Form_Text('name', 'Name')); $email = new T_Form_Text('email', 'Email'); $email->attachFilter(new T_Validate_Email()); $fieldset->addChild($email); $fieldset = new T_Form_Fieldset('prev_jobs', 'Your Previous Jobs'); $form->addChild($fieldset); $repeated = new T_Form_Repeated('jobs', 'Add Another Job', 1, 6); $repeated->addChild(new T_Form_Text('title', 'Title')); $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);
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'); }
<?php define('DEMO', 'Simple Enquiry Form'); require dirname(__FILE__) . '/inc/header.php'; // CREATE FORM $form = new T_Form_Post('contact', 'Send Enquiry'); $fieldset = new T_Form_Fieldset('details', 'Your Details'); $form->addChild($fieldset); $fieldset->addChild(new T_Form_Text('name', 'Name')); $email = new T_Form_Text('email', 'Email'); $email->attachFilter(new T_Validate_Email()); $fieldset->addChild($email); $fieldset = new T_Form_Fieldset('enquiry', 'Your Question'); $form->addChild($fieldset); $comment = new T_Form_TextArea('msg', 'Message'); $fieldset->addChild($comment); $form->setForward($env->getRequestUrl()); // VALIDATE FORM if ($env->isMethod('POST')) { $form->validate($env->input('POST')); } // ACTION FORM if ($form->isPresent() && $form->isValid()) { // action (e.g. email, etc.) echo '<p>Thanks for your submission <a href="mailto:', $form->search('email')->getValue(new T_Filter_Xhtml()), '">', $form->search('name')->getValue(new T_Filter_Xhtml()), '</a>!</p>'; } else { // render form $error = new T_Form_XhtmlError(); $render = new Demo_Form_Xhtml(); $form->accept($error)->accept($render); echo $error, $render;
/** * Search for element. * * @param string $alias alias to search for * @return bool|T_Form_Input element required or false if not found */ function search($alias) { $element = parent::search($alias); if ($element) { return $element; } $children = $this->steps; // leave original pointer intact foreach ($children as $c) { $element = $c->search($alias); if ($element) { return $element; } } return false; }