Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Początek z OOP
Doomin
post 30.10.2011, 10:43:36
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 26.11.2010

Ostrzeżenie: (10%)
X----


Witam zaczynam programować w PHP Obiektowym zrobiłem sobie klasę Formularza znajduję się ona poniżej:

  1. <?php
  2. class Form
  3. {
  4. public $name;
  5. public $method;
  6. public $action;
  7. public $value;
  8. public $checked;
  9. public $onclick;
  10. public $text;
  11. public $cols;
  12. public $rows;
  13.  
  14. public function setOpenForm($name, $method, $action)
  15. {
  16. $this->name = $name;
  17. $this->method = $method;
  18. $this->action = $action;
  19. }
  20.  
  21. public function setCheckboxForm($name, $value, $checked, $text)
  22. {
  23. $this->name = $name;
  24. $this->value = $value;
  25. $this->checked = $checked;
  26. $this->text = $text;
  27. }
  28.  
  29. public function setButtonForm($onclick, $value, $name)
  30. {
  31. $this->onclick = $onclick;
  32. $this->value = $value;
  33. $this->name = $name;
  34. }
  35.  
  36. public function setPasswordForm($name)
  37. {
  38. $this->name = $name;
  39. }
  40.  
  41. public function setTextForm($name)
  42. {
  43. $this->name = $name;
  44. }
  45.  
  46. public function setRadioForm($name, $value, $checked, $text)
  47. {
  48. $this->name = $name;
  49. $this->value = $value;
  50. $this->checked = $checked;
  51. $this->text = $text;
  52. }
  53.  
  54.  
  55. public function setTextareaForm($name, $cols, $rows, $text)
  56. {
  57. $this->name = $name;
  58. $this->cols = $cols;
  59. $this->rows = $rows;
  60. $this->text = $text;
  61. }
  62.  
  63.  
  64.  
  65.  
  66. //Wyświetlanie wyników
  67. public function getOpenForm()
  68. {
  69. return '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'">';
  70. }
  71.  
  72. public function getCheckboxForm()
  73. {
  74. return '<label><input type="checkbox" name="'.$this->name.'" value="'.$this->value.'"/>'.$this->text.'</label>';
  75. }
  76.  
  77. public function getButtonForm()
  78. {
  79. return '<input type="button" value="'.$this->value.'" class="button" style="width:60px;" onclick="'.$this->onclick.'">';
  80. }
  81.  
  82. public function getPasswordForm()
  83. {
  84. return '<input type="password" value="'.$this->value.'" class="textbox" style="width:250px;" name="'.$this->name.'">';
  85. }
  86.  
  87. public function getTextForm()
  88. {
  89. return '<input type="text" value="'.$this->value.'" class="textbox" style="width:250px;" name="'.$this->name.'">';
  90. }
  91.  
  92. public function getRadioForm()
  93. {
  94. return '<label><input type="radio" name="'.$this->name.'" value="'.$this->value.'"/>'.$this->text.'</label>';
  95. }
  96.  
  97. public function getTextareaForm()
  98. {
  99. return '<textarea class="textbox" style="width:250px;" name="'.$this->name.'">'.$this->text.'</textarea>';
  100. }
  101.  
  102. }
  103. ?>


I tutaj pytanie do doświadczonych użytkowników czy to jest dobra klasa bo mi wydaję się że nie i jakie błędy popełniłem klasę wywołuję przez:

  1. <?php
  2. $form = new Form;
  3. $form->setOpenForm('name', 'method', 'action');
  4.  
  5. $form->getOpenForm();
  6. ?>

Go to the top of the page
+Quote Post

Posty w temacie
- Doomin   [PHP]Początek z OOP   30.10.2011, 10:43:36


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 10:30