Location: PHPKode > scripts > RSPA > rspa/components/Form.class.php
<?php

/**
  *
   *
  *  Author : Sunish Kumar M.V
  *
  *  This is licenced under LGPL licence.
  * 
  **/
  
require_once("Component.class.php");
require_once("Button.class.php");
require_once("Checkbox.class.php");
require_once("Hidden.class.php");
require_once("Autocomplete.class.php");
require_once("Radio.class.php");
require_once("Select.class.php");
require_once("Text.class.php");
require_once("Textarea.class.php");
require_once("Label.class.php");
require_once("FCKEditors.class.php");
   
function __autoload($class_name) {
   require_once $class_name . '.class.php';
}

class Form {
	
	
	var $controls = array() ;
	var $redirectUrl="";
	var $clientJs="";
	
    function Form() {
    	//$this->initialize();
    }
    
    function initialize() {
    	$keys = array_keys($_REQUEST);
    	foreach($keys as $key){
    		if($key=="__methord" || $key=="__class" || $key=="__parameters" || $key=="" || (!strstr($key,"___"))){
    		 continue;	
    		}
    		//print($_REQUEST[$key]."<br>");
    		
    		list($type,$name) = split("___",$key);
    		
    		//print("Type: " . $type . ", Name: ".$name.", Key: " . $key  . "\n");
    		
    	    switch($type) {
    	      case 'submit':    	      		
    	      case 'button':
    	      		 $this->controls[$name]	=& new Button($name,$_REQUEST[$key]);
		             break;
		      case 'hidden':
		      case 'password':
		      case 'text':
		      		 $this->controls[$name]	=& new Text($name,$_REQUEST[$key]);
		             break;
		      case 'textarea':
		      		 $this->controls[$name]	=& new Textarea($name,$_REQUEST[$key]);
		             break;
		      case 'select':
		      case 'select-one':
		      case 'select-multiple':
		      		 $this->controls[$name]	=& new Select($name,$_REQUEST[$key]);
		             break;
		      case 'checkbox' : 
		      		 $this->controls[$name]	=& new Checkbox($name,$_REQUEST[$key]);
		             break;
		      case 'radio' : 
		      		 $this->controls[$name]	=& new Radio($name,$_REQUEST[$key]);
		             break;
		      case 'label':
		      		 $this->controls[$name]	=& new Label($name,$_REQUEST[$key]);
		      		 break;
		      case 'autocomplete':
		       		 $this->controls[$name]	=& new Autocomplete($name,$_REQUEST[$key]);
		      		 break;
     		   case 'FCKEditor':
     	          			 $this->controls[$name]	=& new FCKEditors($name,$_REQUEST[$key]);
     	          			 break;
		      default:
		           $this->controls[$name]	=& new Component($name,$_REQUEST[$key]);
		           break;
    	    	
    	    }
    		
    		//$this->controls[$key]	=& new Component($key,$_REQUEST[$key]);
    		//echo($key);
    	}
    	
    	
    }
    
    function redirect($url){
    	
    	$this->redirectUrl=$url;
    }
    
    function clientExecute($js){
    	
    	$this->clientJs .= $js;
    	
    }
    
    function getXml() {
    	$xml = "<rspa><components>";
    	$keys = array_keys($this->controls);
    	foreach($keys as $key){
    		
    		if( $key=="__class" || $key=="__methord"){
    			continue;
    		}
         $xml .= $this->controls[$key]->getComponentXml();	
    		
    		
    		
    	}
    	if(! empty($this->clientJs) ){
    		
    		$xml .= "<clientJs>".htmlspecialchars($this->clientJs)."</clientJs>";
    	}
    	$xml .= "</components>";
    	
    	if(! empty($this->redirectUrl) ){
    		
    		$xml .= "<redirect>".htmlspecialchars($this->redirectUrl)."</redirect>";
    	}
    	
    	
    	
    	$xml .="</rspa>";
    	return $xml;
    }
    
    function getAutoCompleteChoice() {
    	
    	$keys = array_keys($this->controls);
    	foreach($keys as $key){
    		
    		if( $key=="__class" || $key=="__methord"){
    			continue;
    		}
    		if(is_a($this->controls[$key], 'Autocomplete')){
    			return $this->controls[$key]->getAutoCompleteChoice();	
    		}
    		
    	}
    	
    }
    
}
?>
Return current item: RSPA