Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Proste Tworzenie formularza
zietas
post
Post #1





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 11.06.2007

Ostrzeżenie: (0%)
-----


Raczkuje w OOP.
Napisałem nasępujący powiedzmy sobie szczerze 'bardzo prosty generator formularza'.
  1. <?php
  2. class FormGenerator
  3. {
  4.  
  5. public function formOpen($action,$file)
  6. {
  7. if($file)
  8. {
  9. return $formStart = '<form method="post" action="'.$action.'" enctype="multipart/form-data">';
  10. }
  11. else
  12. {
  13. return $formStart = '<form method="post" action="'.$action.'">';
  14. }
  15. }
  16.  
  17. public function formInput($label,$type,$name)
  18. {
  19. return $input = ' <label for="'.$name.'">'.$label.'</label>: <input type="'.$type.'" name="'.$name.'" id="'.$name.'" />';
  20. }
  21.  
  22. public function formTextarea($label,$name,$char_width,$num_lines)
  23. {
  24. return $textarea = '<label for="'.$name.'">'.$label.'</label>: <textarea name="'.$name.'" cols="'.$char_width.'" rows="'.$num_lines.'" id="'.$name.'"></textarea>';
  25. }
  26.  
  27. public function formSelect($label,$name,$value,$option)
  28. {
  29. return $select = '<label for="'.$name.'">'.$label.'</label>: <select name="'.$name.'" id="'.$name.'"><option value="'.$value.'">'.$option.'</option></select>';
  30. }
  31.  
  32. public function formBtn($type,$value,$close)
  33. {
  34. if($close)
  35. {
  36. return $input = '<input type="'.$type.'" value="'.$value.'" /></form>';
  37. }
  38. else
  39. {
  40. return $input = '<input type="'.$type.'" value="'.$value.'" />';
  41. }
  42. }
  43. }
  44. ?>


No i moj formularz tworze nastepujaco:
  1. <?php
  2. require_once('class.FormGenerator.php');
  3.  
  4. $form = new FormGenerator();
  5.  
  6. echo $form->formOpen('contact.php',false);
  7. echo $form->formInput('Pierwszy','text','pierwszy_text');
  8. echo $form->formInput('Drugi','text','drugi_text');
  9. echo $form->formBtn('submit','Send',true);
  10. ?>


Czy jest to w miare poprawne?
Czy musze inaczej do tego podejsc? Jezeli tak, to jak?
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 14.10.2025 - 13:10