Overview

Namespaces

  • None
  • PHP
  • picon

Classes

  • AbstractAjaxBehaviour
  • AbstractAssociatedMarkupSource
  • AbstractBehaviour
  • AbstractCallableOption
  • AbstractChoice
  • AbstractColumn
  • AbstractContextLoader
  • AbstractDatabaseDriver
  • AbstractInjectedDataProvider
  • AbstractJQueryBehaviour
  • AbstractJQueryUIBehaviour
  • AbstractLink
  • AbstractMarkupSource
  • AbstractMultipleChoice
  • AbstractOption
  • AbstractPageClassAuthorisationStrategy
  • AbstractRepeater
  • AbstractSingleChoice
  • AbstractTextComponent
  • AbstractToolbar
  • AbstractValidator
  • AjaxButton
  • AjaxEventBehaviour
  • AjaxFormComponentUpdateBehavior
  • AjaxFormSubmitBehavior
  • AjaxLink
  • AjaxRequestTarget
  • AllowAllAuthorisationStrategy
  • AnnotationRule
  • ApplicationConfigLoadListener
  • ApplicationContext
  • ApplicationContextLoadListener
  • ApplicationInitializer
  • ApplicationInitializerConfigLoadListenerCollection
  • ApplicationInitializerContextLoadListenerCollection
  • ApplicationProfile
  • Args
  • ArrayModel
  • ArrayOption
  • AttributeAppender
  • AttributeModifier
  • AutoContextLoader
  • AutoLoader
  • BasicModel
  • BooleanModel
  • BooleanOption
  • Border
  • BorderMarkupSourcingStratagy
  • BorderResolver
  • Button
  • CacheManager
  • CallbackAjaxCallDecorator
  • CallbackColumn
  • CallbackFunctionOption
  • CallbackOption
  • CallbackRowMapper
  • Check
  • CheckBox
  • CheckBoxGroup
  • CheckChoice
  • ChoiceRenderer
  • ClassNameRule
  • ClassNamespaceRule
  • ClassScanner
  • Comment
  • ComonDomainBase
  • Component
  • ComponentAfterRenderListenerCollection
  • ComponentAuthorisationListener
  • ComponentBeforeRenderListenerCollection
  • ComponentInitializationListenerCollection
  • ComponentInjector
  • ComponentInstantiationListenerCollection
  • ComponentRenderHeadListenerCollection
  • ComponentResolverHelper
  • ComponentTag
  • CompoundPropertyModel
  • Config
  • ConfigLoader
  • ContextLoaderFactory
  • DaoSupport
  • DataBaseTemplate
  • DataGridView
  • DataSource
  • DataSourceConfig
  • DataSourceFactory
  • DataSourceType
  • DataTable
  • DateField
  • DatePickerBehaviour
  • DefaultDataTable
  • DefaultJQueryUIBehaviour
  • DefaultMarkupSource
  • DefaultNotAuthorisedListener
  • DialogBehavior
  • DirectToPageComponentNotAuthorisedListener
  • DraggableBehaviour
  • DropDown
  • EmailAddressValidator
  • EmptyPanel
  • Enum
  • ExceptionPageRequestTarget
  • ExtendResolver
  • FeedbackMessage
  • FeedbackModel
  • FeedbackPanel
  • FileModel
  • FileUploadField
  • Form
  • FormComponent
  • FormComponentLabel
  • FormComponentPanel
  • FunctionOption
  • GridItem
  • GridView
  • HeaderContainer
  • HeaderPartContainer
  • HeaderResolver
  • HeaderResponse
  • HeaderToolbar
  • IdenticalValueValidator
  • Identifier
  • Injector
  • JQueryRenderHeadListener
  • JQueryUIRenderHeadListener
  • Label
  • LabeledMarkupContainer
  • Link
  • ListenerCollection
  • ListenerRequestResolver
  • ListenerRequestTarget
  • ListItem
  • ListMultiple
  • ListView
  • Localizer
  • ManualContextLoader
  • MarkupContainer
  • MarkupElement
  • MarkupLoader
  • MarkupParser
  • MarkupUtils
  • MaximumLengthValidator
  • MaximumValidator
  • MinimumLengthValidator
  • MinimumValidator
  • ModalWindow
  • MySqlDriver
  • MySqliDriver
  • NavigationLink
  • NavigationToolbar
  • Navigator
  • NumbericOption
  • NumericValidator
  • Objects
  • Options
  • PageInstanceRequestResolver
  • PageInstanceRequestTarget
  • PageMap
  • PageMapInitializationListenerCollection
  • PageNotFoundPage
  • PageNotFoundRequestTarget
  • PageRequestResolver
  • PageRequestTarget
  • PageRequestWithListenerTarget
  • PaginatingGridView
  • Panel
  • PanelMarkupSource
  • PanelResolver
  • PasswordField
  • PatternValidator
  • PiconApplication
  • PiconErrorHandler
  • PiconSerializer
  • PiconTag
  • PopupSettings
  • PropertyColumn
  • PropertyModel
  • PropertyOption
  • PropertyResolver
  • Radio
  • RadioChoice
  • RadioGroup
  • RangeLengthValidator
  • RangeValidator
  • RedirectRequestTarget
  • RepeatingView
  • RequestCycle
  • RequestResolverCollection
  • RequiredTextField
  • ResourceReference
  • ResourceRequestResolver
  • ResourceRequestTarget
  • SerializableClosure
  • SortableBehavior
  • StaticTabPanel
  • StringValidator
  • SubClassRule
  • Tab
  • TabCollection
  • TabPanel
  • TextArea
  • TextElement
  • TextField
  • TransparentMarkupContainer
  • ValidatableFormComponentWrapper
  • ValidationResponse
  • WebApplicationSecuritySettings
  • WebComponent
  • WebPage
  • WebRequest
  • WebResponse
  • WrappedCompoundModel
  • XMLDocument
  • XMLParser
  • XMLTag
  • XmlTagType

Interfaces

  • AjaxCallDecorator
  • ApplicationInitializerConfigLoadListener
  • ApplicationInitializerContextLoadListener
  • AuthorisationStrategy
  • Behaviour
  • BehaviourListener
  • CallDecoratorWrapper
  • ChoiceGroup
  • ClassScannerRule
  • Column
  • ComponentAfterRenderListener
  • ComponentAwareModel
  • ComponentBeforeRenderListener
  • ComponentInheritedModel
  • ComponentInitializationListener
  • ComponentInstantiationListener
  • ComponentNotAuthorisedListener
  • ComponentRenderHeadListener
  • ComponentResolver
  • CompoundModel
  • DatabaseDriver
  • DataBaseOperations
  • DataProvider
  • Detachable
  • Equalable
  • FormSubmitListener
  • FormSubmitter
  • Identifiable
  • InitializingBean
  • InjectOnWakeup
  • LinkListener
  • Listener
  • MarkupSource
  • Model
  • Pageable
  • PageMapInitializationListener
  • Request
  • RequestablePage
  • RequestResolver
  • RequestTarget
  • Response
  • RowMapper
  • Validatable
  • Validator
  • XmlElement

Exceptions

  • ConfigException
  • ConversionException
  • RestartRequestOnPageException
  • SQLException
  • UnAuthorisdeException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * Picon Framework
  5:  * http://code.google.com/p/picon-framework/
  6:  *
  7:  * Copyright (C) 2011-2012 Martin Cassidy <martin.cassidy@webquub.com>
  8: 
  9:  * Picon Framework is free software: you can redistribute it and/or modify
 10:  * it under the terms of the GNU General Public License as published by
 11:  * the Free Software Foundation, either version 3 of the License, or
 12:  * (at your option) any later version.
 13: 
 14:  * Picon Framework is distributed in the hope that it will be useful,
 15:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17:  *  General Public License for more details.
 18: 
 19:  * You should have received a copy of the GNU General Public License
 20:  * along with Picon Framework.  If not, see <http://www.gnu.org/licenses/>.
 21:  * */
 22: 
 23: namespace picon;
 24: 
 25: /**
 26:  * A form which will contain form component.
 27:  * This will process and validate the post data when the callback is invoked.
 28:  * If a form is submitted with a button, the appropriate button callback will also
 29:  * be invoked
 30:  * 
 31:  * @author Martin Cassidy
 32:  * @package web/markup/html/form
 33:  */
 34: class Form extends MarkupContainer implements FormSubmitListener
 35: {
 36:     private $onSubmit;
 37:     private $onError;
 38:     
 39:     public function __construct($id, $model = null, $onSubmit = null, $onError = null)
 40:     {
 41:         parent::__construct($id, $model);
 42:         if($onError!=null)
 43:         {
 44:             Args::callBack($onError, 'onError');
 45:             $this->onError = $onError;
 46:         }
 47:         if($onSubmit!=null)
 48:         {
 49:             Args::callBack($onSubmit, 'onSubmit');
 50:             $this->onSubmit = $onSubmit;
 51:         }
 52:     }
 53:     
 54:     protected function onComponentTag(ComponentTag $tag)
 55:     {
 56:         parent::onComponentTag($tag);
 57:         $this->checkComponentTag($tag, 'form');
 58:         $tag->put('action', $this->urlForListener($this));
 59:         $tag->put('method', 'post');
 60:     }
 61:     
 62:     /**
 63:      * Called when the form is submited
 64:      * @todo sort out code for nested forms
 65:      */
 66:     public function onEvent()
 67:     {
 68:         $formToProcess = $this;
 69:      
 70:         $submitter = $this->getSubmitingButton();
 71:         
 72:         if($submitter!=null)
 73:         {
 74:             $formToProcess = $submitter->getForm();
 75:         }
 76:         $formToProcess->process($submitter);
 77:     }
 78:     
 79:     public function process(FormSubmitter $submitter)
 80:     {
 81:         if($this->getRequest()->isPost())
 82:         {
 83:             $components = array();
 84:             $form = $this;
 85:             $callback = function(&$component) use (&$components, $form)
 86:             {
 87:                 if($component->getForm()!=$form)
 88:                 {
 89:                     return Component::VISITOR_CONTINUE_TRAVERSAL_NO_DEEPER;
 90:                 }
 91:                 array_push($components, $component);
 92:                 return Component::VISITOR_CONTINUE_TRAVERSAL;
 93:             };
 94:             $this->visitChildren(FormComponent::getIdentifier(), $callback);
 95: 
 96:             foreach($components as $formComponent)
 97:             {
 98:                 $formComponent->inputChanged();
 99:             }
100:             
101:             $formValid = true;
102:             foreach($components as $formComponent)
103:             {
104:                 $formComponent->validate();
105:                 if(!$formComponent->isValid())
106:                 {
107:                     $formValid = false;
108:                 }
109:             }
110:             
111:             if($formValid)
112:             {
113:                 foreach($components as $formComponent)
114:                 {
115:                     $formComponent->updateModel();
116:                 }
117:                 $this->callSubmit($submitter);
118:             }
119:             else
120:             {
121:                 $this->callOnError($submitter);
122:             }
123:         }
124:     }
125:     
126:     public function isFormValid()
127:     {
128:         $valid = true;
129:         $callback = function(FormComponent &$component) use (&$valid)
130:         {
131:             if(!$component->isValid())
132:             {
133:                 $valid = false;
134:                 return Component::VISITOR_STOP_TRAVERSAL;
135:             }
136:             return Component::VISITOR_CONTINUE_TRAVERSAL;
137:         };
138:         $this->visitChildren(FormComponent::getIdentifier(), $callback);
139:         return $valid;
140:     }
141:     
142:     public function getSubmitingButton()
143:     {
144:         $button = null;
145:         $request = $this->getRequest();
146:         $callback = function(Button &$component) use (&$button, $request)
147:         {
148:             $value = $request->getPostedParameter($component->getName());
149:             if($value!=null)
150:             {
151:                 $button = $component;
152:                 return Component::VISITOR_STOP_TRAVERSAL;
153:             }
154:             return Component::VISITOR_CONTINUE_TRAVERSAL;
155:         };
156:         $this->visitChildren(Button::getIdentifier(), $callback);
157:         return $button;
158:     }
159:     
160:     private function callOnError($submiter)
161:     {
162:         $this->onError();
163:         if($submiter!=null && $submiter instanceof FormSubmitter)
164:         {
165:             $submiter->onError();
166:         }
167:     }
168:     
169:     private function callSubmit($submiter)
170:     {
171:         $this->onSubmit();
172:         if($submiter!=null && $submiter instanceof FormSubmitter)
173:         {
174:             $submiter->onSubmit();
175:         }
176:     }
177:     
178:     public function onError()
179:     {
180:         if(is_callable($this->onError))
181:         {
182:             $callable = $this->onError;
183:             $callable();
184:         }
185:     }
186:     
187:     public function onSubmit()
188:     {
189:         if(is_callable($this->onSubmit))
190:         {
191:             $callable = $this->onSubmit;
192:             $callable();
193:         }
194:     }
195:     
196:     public function beforeComponentRender()
197:     {
198:         parent::beforeComponentRender();
199:         $multipart = false;
200:         $callback = function(&$component) use (&$multipart)
201:         {
202:             if($component->isMultiPart())
203:             {
204:                 $multipart = true;
205:             }
206:             return Component::VISITOR_CONTINUE_TRAVERSAL;
207:         };
208:         $this->visitChildren(FormComponent::getIdentifier(), $callback);
209:         
210:         if($multipart)
211:         {
212:             $this->add(new AttributeModifier('enctype', new BasicModel('multipart/form-data')));
213:         }
214:     }
215: }
216: 
217: ?>
218: 
Picon Framework API documentation generated by ApiGen 2.7.0