Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Funckja i lista rozwijana
koreja
post
Post #1





Grupa: Zarejestrowani
Postów: 120
Pomógł: 22
Dołączył: 15.07.2008
Skąd: Raniżów/Rzeszów

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


Witam. Mam mały problem, mianowicie zbudowałem taką funkcję:

  1. <?php
  2. function buildOptions($options, $selectedOption) {
  3.    foreach($options as $value => $desc) {
  4.        if($value == $selectedOption) {
  5.            print '<option value "' . $value . '" selected="selected" name="'.$value.'">' . $desc . '</option>';
  6.        } else {
  7.            print '<option value"' . $value . '" name="'.$value.'">' . $desc . '</option>';
  8.        }
  9.    }
  10. }
  11. ?>


Wklejam ją do poniższego formularza:
strona.php
  1. <form action="strona.php" method="post">
  2. <label for="opt">Opcje:</label>
  3. <select id="opt" name="opt"><?php buildOptions($options); ?></select><br />
  4. <input type="submit" value="Dalej" name="submit" />
  5. </form>


Gdy wchodzę na stronkę z tym formularzem, lista jest poprawna, jednak po wyborze opcji i kliknięciu na "Dalej" listy już nie ma. A sprawdzenie
  1. <?php echo $_POST['opt']; ?>
nie pokazuje nic.

W czym może być problem?

Ten post edytował koreja 10.01.2009, 14:27:05
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
koreja
post
Post #2





Grupa: Zarejestrowani
Postów: 120
Pomógł: 22
Dołączył: 15.07.2008
Skąd: Raniżów/Rzeszów

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


Aha (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Plik register.php

  1. <?php include('reg.func.php');
  2.  
  3. if(isset($_POST['submit']) && $_POST['submit'] == "Rejestruj") {
  4.  
  5. ?>
  6. <fieldset id="register">
  7. <legend>Rejestracja nowego użytkownika:</legend>
  8. <form action="register.php" method="post">
  9. <label for="state">Województwo:</label><?php isValidState(); ?>
  10. <input type="submit" name="submit" style="margin-left:150px;" value="Rejestruj" />
  11. </form>
  12. <?php } else {
  13. ?>
  14. <fieldset id="register">
  15. <legend>Rejestracja nowego użytkownika:</legend>
  16. <form action="register.php" method="post">
  17. <label for="state">Województwo:</label>
  18. <select id="state" name="state"><?php buildOptions($stateOptions); ?></select><br />
  19. <input type="submit" name="submit" style="margin-left:150px;" value="Rejestruj" />
  20. </form>
  21. <?php }
  22. ?>


reg.func.php
  1. <?php
  2. function isValidState() {
  3.            if($_POST['state'] != '0') {
  4.                print '<select id="state" name="state">'; buildOptions($stateOptions, $_POST['state']); print '</select><br />';
  5.                $valid = true;
  6.                }
  7.                else {
  8.                print '<select id="state" name="state">'; buildOptions($stateOptions); print '</select><br />';
  9.                }
  10.            }
  11. ?>


Ten post edytował koreja 10.01.2009, 15:08:50
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: 26.12.2025 - 23:07