Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ZendFramework]Dynamiczne dodawanie elementów formularza
Keg
post
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 12.11.2010

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


Tak jak w temacie od początku weekendu próbuje stworzyć dynamiczny formularz który będzie dodawał wyznaczone elementy. Znalazłem i wykonałem ten tutorial http://www.jeremykendall.net/2009/01/19 … zend-form/ , a chcąc aby zamiast jednego pola dodawał mi dwa, przerobiłem funkcje znajdujące się w formularzu. Teraz wyglądają u mnie tak

  1. public function preValidation(array $data) {
  2. function findFields($field) {
  3. if (strpos($field, 'newName') !== false) {
  4. return $field;
  5. }
  6. if (strpos($field, 'newInfo') !== false) {
  7. return $field;
  8. }
  9. }
  10. $newFields = array_filter(array_keys($data), 'findFields');
  11. foreach ($newFields as $fieldName) {
  12. if (strpos($fieldName, 'newName') !== false) {
  13. $order = ltrim($fieldName, 'newName') + 2;
  14. $this->addNewField($fieldName, $data[$fieldName], $order);
  15. }
  16. if (strpos($fieldName, 'newInfo') !== false) {
  17. $order = ltrim($fieldName, 'newInfo') + 2;
  18. $this->addNewInfo($fieldName, $data[$fieldName], $order);
  19. }
  20. }
  21. }
  22.  
  23. public function addNewField($name, $value, $order) {
  24. $next_proposal = new Zend_Form_Element_Text($name);
  25. $next_proposal->setRequired(true)
  26. ->setOrder($order)
  27. ->setValue($value)
  28. ->setLabel('Nazwa propozycji: ')
  29. ->setAttrib('size', '40')
  30. ->addFilters(array(
  31. new Zend_Filter_StringToLower('UTF-8'),
  32. new Zend_Filter_StringTrim(),
  33. new Zend_Filter_StripNewlines(),
  34. new Zend_Filter_StripTags()
  35. ))
  36. ->addValidators(array(
  37. new Zend_Validate_NotEmpty(),
  38. new Zend_Validate_StringLength(3, 100),
  39. new Zend_Validate_Regex('/^[a-zA-Z0-9 -]+$/'),
  40. new Zend_Validate_Db_NoRecordExists('proposals', 'title')
  41. ));
  42. $this->addElement($next_proposal);
  43. }
  44.  
  45. public function addNewInfo($name, $value, $order) {
  46. $next_info = new Zend_Form_Element_Textarea($name);
  47. $next_info->setLabel('Opisz propozycje: ')
  48. ->setValue($value)
  49. ->setOrder($order)
  50. ->setRequired(TRUE)
  51. ->setAttribs(array(
  52. 'cols' => 10,
  53. 'rows' => 5
  54. ))
  55. ->addFilters(array(
  56. new Zend_Filter_StringTrim(),
  57. new Zend_Filter_StripTags()
  58. ))
  59. ->addValidators(array(
  60. new Zend_Validate_NotEmpty(),
  61. new Zend_Validate_StringLength(250, 6000)
  62. ));
  63. $this->addElement($next_info);
  64. }


Problem w tym że gdy funkcje wykonują się przy próbie walidacji otrzymuje wyłącznie elementy textarea, natomiast elementy text nie są wyświetlane.

Będę wdzięczny za wszystkie rady.
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 21.08.2025 - 15:03