Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] Problem z radio buttonami
marek2003
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 22.11.2007

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


Witam

Mam taki kod:
  1. <?php
  2.  
  3. for ($i=1; $i <= $liczba; $i++)
  4.  
  5. {
  6. echo"<br><p style='text-align: right; font-size: 15'>Wymiar A$i <input type=\"text\" name=\"wymiarA[]\" maxlength=\"3\" size=\"2\">";
  7. echo"<br>Prawo<input type=\"radio\" name=\"pole_".$i."\" value=\"prawo\" checked=\"checked\">";
  8. echo"Lewo<input type=\"radio\" name=\"pole_".$i."\" value=\"lewo\">";
  9. echo"Góra<input type=\"radio\" name=\"pole_".$i."\" value=\"gora\">";
  10. echo"Dół<input type=\"radio\" name=\"pole_".$i."\" value=\"dol\">";
  11. echo"<br>";
  12. } 
  13.  
  14. ?>


Jak widać, zostanie wygenerowany formularz z textboxem i czterema radio buttonami (powielony tyle razy, ile wynosi "liczba"). Mój problem jest następujący. Jak widać, name radio buttona zawiera zmienną $i. Chcialbym teraz wykonać sprawdzenie (oczywiście w pętli) typu: dla wymiaru A$i kierunek jest:... (np. prawo). Ta zmienna w name wszystko komplikuje, bez niej łatwo jest przesłać value używając np. $kierunek = $_POST['pole']; ale jak wsadzić tam jeszcze zmienną $i (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) ?
Powód edycji: Dodałem tag @drPayton
Go to the top of the page
+Quote Post
Cezar708
post
Post #2





Grupa: Zarejestrowani
Postów: 1 116
Pomógł: 119
Dołączył: 10.05.2005
Skąd: Poznań

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


zamiast:
Cytat(marek2003 @ 13.12.2007, 15:08:41 ) *
  1. <?php
  2.  
  3. for ($i=1; $i <= $liczba; $i++)
  4.  
  5. {
  6. echo"<br><p style='text-align: right; font-size: 15'>Wymiar A$i <input type=\"text\" name=\"wymiarA[]\" maxlength=\"3\" size=\"2\">";
  7. echo"<br>Prawo<input type=\"radio\" name=\"pole_".$i."\" value=\"prawo\" checked=\"checked\">";
  8. echo"Lewo<input type=\"radio\" name=\"pole_".$i."\" value=\"lewo\">";
  9. echo"Góra<input type=\"radio\" name=\"pole_".$i."\" value=\"gora\">";
  10. echo"Dół<input type=\"radio\" name=\"pole_".$i."\" value=\"dol\">";
  11. echo"<br>";
  12. } 
  13.  
  14. ?>


użyj:
  1. <?php
  2.  
  3. for ($i=1; $i <= $liczba; $i++)
  4.  
  5. {
  6. echo"<br><p style='text-align: right; font-size: 15'>Wymiar A$i <input type=\"text\" name=\"wymiarA[]\" maxlength=\"3\" size=\"2\">";
  7. echo"<br>Prawo<input type=\"radio\" name=\"pole_[".$i."]\" value=\"prawo\" checked=\"checked\">";
  8. echo"Lewo<input type=\"radio\" name=\"pole[".$i."]\" value=\"lewo\">";
  9. echo"Góra<input type=\"radio\" name=\"pole[".$i."]\" value=\"gora\">";
  10. echo"Dół<input type=\"radio\" name=\"pole[".$i."]\" value=\"dol\">";
  11. echo"<br>";
  12. } 
  13.  
  14. ?>


a potem w skrypcie obsługującym, możesz:

  1. <?php
  2. foreach ( $_POST['pole'] as $key => $kierunek ){
  3. echo "A$key jest w $kierunek";
  4. }
  5. ?>
Go to the top of the page
+Quote Post
marek2003
post
Post #3





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 22.11.2007

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


GENIALNE!!!

Dokładnie o takie coś mi chodziło, wielkie wielkie dzięki!!! (IMG:http://forum.php.pl/style_emoticons/default/yahoo.gif)
Go to the top of the page
+Quote Post

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: 19.12.2025 - 13:30