method = $method; $this->name = $name; $this->action = $action; } /** * Sets the property $name to $value. * * @throws ezcBasePropertyNotFoundException if the property does not exist. * @param string $name * @param mixed $value * @ignore */ public function __set( $name, $value ) { switch ( $name ) { case 'method': case 'name': case 'action': case 'redirectUrl': $this->properties[$name] = $value; break; case 'hasReceivedData': case 'signals': throw new ezcBasePropertyPermissionException( $name, ezcBasePropertyPermissionException::READ ); break; default: parent::__set( $name, $value ); break; } } /** * Returns the property $name. * * @throws ezcBasePropertyNotFoundException if the property does not exist. * @param string $name * @return mixed * @ignore */ public function __get( $name ) { switch ( $name ) { case 'signals': if( !isset( $this->properties[$name] ) ) { $this->properties['signals'] = new ezcSignalCollection( __CLASS__ ); } // no break here... case 'name': case 'hasReceivedData': case 'method': case 'action': case 'redirectUrl': // extend to separate class.. so you can have several elements in this list instead // of just one return isset( $this->properties[$name] ) ? $this->properties[$name] : null; break; default: return parent::__get( $name ); break; } } /** * Registers a form element. * * This method will call setId() on the element with a unique ID for that element.. */ public function registerElement( ezcWgFormFieldElement $f ) { $f->setId( $this->elementCounter++ ); } /** * Renders the start and end form tag and the children within it. * * If this form has a redirectUrl set it will be sent to the form in a hidden field. */ public function render() { $output = "
name}\" method=\"{$this->method}\" action=\"{$this->action}\">"; if( $this->redirectUrl != null ) { $ouput .= "redirectUrl}\" />"; } $output .= $this->renderFormContents(); $output .= "
"; return $output; } /** * Called by render() when the form contens should be rendered. * * The default implementation renders all children. */ public function renderFormContents() { return parent::render(); } /** need to be reimplemented because even if a child accepts a form event * the event it must go through the rest of the children. * maybe add another accept status for this? * * Another options is to stop event handling for form elements and to run dataReceived() for each of them. * All the children have been retrieved using registerElement in the first place. Unfortunately this has drawbacks * when it comes to ajax for example. */ public function handleEvent( ezcWgEvent $e ) { if( $e instanceof ezcWgFormEvent ) { // TODO: change according to event handling // fetch the redirect field if any if( isset( $_POST["FormRedirectMagic"] ) ) { $this->redirectUrl = $_POST["FormRedirectMagic"]; } foreach( $this->children as $child ) { $child->handleEvent( $e ); } if( $e->isAccepted ) { $this->properties['hasReceivedData'] = true; } if( isset( $this->properties['signals'] ) ) { $this->signals->emit( "formEventCompleted" ); } } else { parent::handleEvent( $e ); } } } ?>