mqnoy

belajar oop php

May 16th, 2014
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.05 KB | None | 0 0
  1. <?php
  2.  
  3. class box{
  4.         function displaybox(){
  5.             ?>
  6.             <div class="box">
  7.             <?php
  8.            
  9.         }
  10. }
  11. class CLbox extends box{
  12.         function closebox(){
  13.         ?>
  14.         </div>
  15.         <?php
  16.         }
  17.         }
  18.  
  19. class form{
  20.     var $fields     = array();
  21.     var $totFields  = 0;
  22.     var $thisname="default";
  23.    
  24.    
  25.         function __construct(){
  26.             $this->asend = "send.php";
  27.             $this->amethod = "post";
  28.         }
  29.         function change_form($thisname,$thisaction,$thisMethod){
  30.             $this->asend = $thisaction;
  31.             $this->amethod = $thisMethod;
  32.             $this->thisname = $thisname;
  33.         }
  34.    
  35.         function displayform(){
  36.             ?>
  37.             <form action="<?php print $this->asend;?>" name="<?php print $this->thisname;?>" method="<?php print $this->amethod;?>">
  38.             <?php
  39.             for($op=0; $op<count($this->fields);$op++){
  40.             ?>
  41.             <label><?php print $this->fields[$op]['labelField'];?></label>
  42.             <input type="<?php print $this->fields[$op]['typeField'];?>" name="<?php print $this->fields[$op]['nameField'];?>"/>
  43.             <?php
  44.             }
  45.         }
  46.         function addField($typeField,$nameField,$labelField){
  47.             $this->fields[$this->totFields]['typeField']=$typeField;
  48.             $this->fields[$this->totFields]['nameField']=$nameField;
  49.             $this->fields[$this->totFields]['labelField']=$labelField;
  50.             $this->totFields++;
  51.         }
  52. }
  53. class createButton extends form{
  54.         function showButton($typeButton,$valButton){
  55.         $this->valB=$valButton;
  56.         $this->typeB=$typeButton;
  57.         ?>
  58.         <input type="<?php print $this->typeB;?>" name="nama" value="<?php print $this->valB;?>"/>
  59.         <?php
  60.         }
  61.        
  62.         }
  63.        
  64. class closeF extends form{
  65.         function closeform(){
  66.         ?>
  67.         </form>
  68.         <?php
  69.         }
  70.         }
  71.  
  72.  
  73. $createbox = new box();
  74. $showForm = new form();
  75. $clsBox = new CLbox();
  76. $cls = new closeF;
  77. $BTton = new createButton;
  78. ?>
  79.  
  80. <html>
  81. <body>
  82. <?php
  83. $acc=$_SERVER["PHP_SELF"];
  84. $createbox->displaybox();
  85. $showForm->change_form("nameform","$acc","post");
  86. $showForm ->addField("text","name","label");
  87. $showForm ->addField("radio","name","radio");
  88. $showForm->displayform();
  89. $BTton->showButton("submit","new");
  90. $BTton->showButton("reset","reset");
  91. $cls->closeform();
  92. ?>
  93. </body>
  94. </html>
Advertisement
Add Comment
Please, Sign In to add comment