- <?php
- class TextBox {
- private $control ="";
- private $properties = null;
- private $textmode = "";
- private $textmode_properties ="";
- private $error_message;
- public function __construct(){
- $this->properties = array ( 'Value'=> '', 'Name' => '', 'ID' => '', 'Class' => '', 'MaxLength' => '' );
- }
- public function __get($property){
- return $this->properties['$property'];
- }else{
- }
- }
- public function __set($property, $value){
- return $this->properties[$property] = $value;
- }else{
- }
- }
- public function ErrorMessage($errormessage){
- $this->error_message = "<label>" . $errormessage . "</label>";
- }
- }
- public function TextMode($textmode){
- $this->textmode = $textmode;
- }else{
- }
- }
- private function BuildControl(){
- switch ($this->textmode){
- case 'SingleLine':
- $this->SingleLine();
- break;
- case 'MultiLine':
- $this->MultiLine();
- break;
- case 'Password':
- $this->Password();
- break;
- case 'Hidden':
- $this->Hidden();
- break;
- }
- }else{
- $this->SingleLine();
- }
- }
- private function SingleLine(){
- $this->control = "<input type=\"text\" ";
- foreach( $this->properties as $property => $value ){
- if ( $value !="" ){
- }
- }
- $this->control .= " />" . $this->error_message;
- }
- private function MultiLine(){
- $text = "";
- $this->control = "<textarea ";
- foreach( $this->properties as $property => $value ){
- if ( $property == "Value" ){
- $text = $value;
- }else{
- if ( $value !="" ){
- }
- }
- }
- $this->control .= ">" . $text . "</textarea>" . $this->error_message;
- }
- private function Password(){
- $this->control = "<input type=\"password\" ";
- foreach( $this->properties as $property => $value ){
- if ( $value !="" ){
- }
- }
- $this->control .= " />" . $this->error_message;
- }
- private function Hidden(){
- $this->control = "<input type=\"hidden\" ";
- foreach( $this->properties as $property => $value ){
- if ( $value !="" ){
- }
- }
- $this->control .= " />" . $this->error_message;
- }
- public function __tostring(){
- $this->BuildControl();
- return $this->control;
- }
- }
- ?>
- <?php
- //Usage
- $txtFirstName = new TextBox();
- $txtFirstName->Name = "txtFirstName";
- $txtFirstName->ID = "txtFirstName";
- $txtFirstName->Class = "css_field";
- echo $txtFirstName;
- ?>
PHP - TextBox Class
This TextBox class can be used to create form textbox elements, which can then be inserted into a template file.
No comments:
Post a Comment