Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Tablica w POST?
WoGuziczek
post 20.08.2009, 09:37:15
Post #1





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 17.09.2008

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


Witam!

Mam o to taki fragment funkcji JS:
  1. $$('.programs .checkbox').each(
  2. function(el)
  3. {
  4. el.onclick = function(el)
  5. {
  6. var id = this.id.sub('checkbox-', '', 1);
  7.  
  8. switch (this.className)
  9. {
  10. case 'checkbox':
  11. this.className = 'checkbox-sel';
  12. new Insertion.Top(
  13. this.id,
  14. '<input type="hidden" name="programs[]" value="' + id + '" id="programs-' + id + '"/>'
  15. );
  16. break;
  17.  
  18. case 'checkbox-sel':
  19. this.className = 'checkbox';
  20. if ($('programs-' + id))
  21. {
  22. $('programs-' + id).remove();
  23. }
  24. break;
  25. }
  26. }
  27. }
  28. )


Teraz tak - jeżeli będę miał zaznaczony checkbox to ma zostać ukryte pole hidden.
ok, ale tych pól jest u mnie 7 a każde reprezentuje inną wartość.

To pole wygląda tak:
  1. <input type="hidden" name="programs[]" value="' + id + '" id="programs-' + id + '"/>


I jak mam z tego po kolei wyciągać i sprawdzać, czy któreś pola są zaznaczone?
Metoda POST.

Pozdrawiam
Powód edycji: dodałem tag (cysiaczek)
Go to the top of the page
+Quote Post
nospor
post 20.08.2009, 09:51:49
Post #2





Grupa: Moderatorzy
Postów: 36 447
Pomógł: 6292
Dołączył: 27.12.2004




  1. print_r($_POST);

I moze cie olsni smile.gif


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
WoGuziczek
post 20.08.2009, 10:00:47
Post #3





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 17.09.2008

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


Olśniło mnie, ale nie do końca...

Efektem kodu:
  1. $_POST['programs[]'] = 1;
  2. $_POST['programs[]'] = 2;
  3. $_POST['programs[]'] = 3;
  4. $_POST['programs[]'] = 4;
  5. $_POST['programs[]'] = 5;
  6. $_POST['programs[]'] = 6;
  7. $_POST['programs[]'] = 7;
  8.  
  9.  
  10. echo print_r($_POST);


jest

  1. Array ( [programs[]] => 7 ) 1


A to mi za dużo nie mówi...

A np. kod:
  1. $_POST['programs[]'] = 1;
  2. $_POST['programs[]'] = 2;
  3. $_POST['programs[]'] = 3;
  4. $_POST['programs[]'] = 4;
  5. $_POST['programs[]'] = 5;
  6. $_POST['programs[]'] = 6;
  7. $_POST['programs[]'] = 7;
  8.  
  9. $tablica = $_POST['programs[]'];
  10.  
  11. echo print_r($tablica);


Zwróci mi wynik 71

Ten post edytował WoGuziczek 20.08.2009, 10:04:46
Go to the top of the page
+Quote Post
cojack
post 20.08.2009, 10:07:29
Post #4





Grupa: Zarejestrowani
Postów: 898
Pomógł: 80
Dołączył: 31.05.2008

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


php tego-> programs[] z html'a nie przepuści na tablice.


--------------------
cojack blog - mój blog (na jakiś czas off).
"jak czegoś nie wiem, to nie myślę że wiem" - moja domena
Go to the top of the page
+Quote Post
WoGuziczek
post 20.08.2009, 10:16:18
Post #5





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 17.09.2008

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


a no właśnie... jakaś pętla?
Go to the top of the page
+Quote Post
Cysiaczek
post 20.08.2009, 10:19:27
Post #6





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Tak, pętla
  1. foreach($_POST['programs'] as $key=>$value){}


Przenoszę na przedszkole


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
WoGuziczek
post 20.08.2009, 10:27:53
Post #7





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 17.09.2008

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


Warning: Invalid argument supplied for foreach()

// oczywiście zrobiłem wyświetlanie wewnątrz pętli.

Ten post edytował WoGuziczek 20.08.2009, 10:28:43
Go to the top of the page
+Quote Post
Cysiaczek
post 20.08.2009, 10:31:31
Post #8





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




Oj kolego, bo się pogniewamy.
Czy zrobiłeś to, co napisał Tobie ~nospor, żeby zobaczyć jaka jest struktura tablicy przekazanej metodą POST z formularza?


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
Go to the top of the page
+Quote Post
cojack
post 20.08.2009, 10:32:57
Post #9





Grupa: Zarejestrowani
Postów: 898
Pomógł: 80
Dołączył: 31.05.2008

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


Nie, on zrobił to:
  1. $_POST['programs[]'] = 1;
  2. $_POST['programs[]'] = 2;
  3. $_POST['programs[]'] = 3;
  4. $_POST['programs[]'] = 4;
  5. $_POST['programs[]'] = 5;
  6. $_POST['programs[]'] = 6;
  7. $_POST['programs[]'] = 7;

i myśli że ma tablice.

A ma wysłać formularz, i zrobić sobie print na $_POST'a. Czytanie ze zrozumieniem, przydaje się na maturze.

Ten post edytował cojack 20.08.2009, 10:34:03


--------------------
cojack blog - mój blog (na jakiś czas off).
"jak czegoś nie wiem, to nie myślę że wiem" - moja domena
Go to the top of the page
+Quote Post
WoGuziczek
post 20.08.2009, 10:49:40
Post #10





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 17.09.2008

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


Ok! Wszystko wiem.

Dzięki bardzo winksmiley.jpg
Śmiga.
Go to the top of the page
+Quote Post

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: 20.04.2024 - 06:19