Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Wybór szablonu poprzez formularz
Forum PHP.pl > Forum > Przedszkole
Kshyhoo
W folderze themes przechowuję foldery z szablonami. Wczytuję zawartość tego folderu i wyświetlam w selekcie. Wybieram skórę i zapisuję ustawienie. Napisałem skrypt, ale nie działa. Help!
  1. <?php
  2. function theme_set()
  3. {
  4. echo &#092;"<center><form action='\".$DefaultTheme.\".php' method='post'>\"
  5. .&#092;"<select name='DefaultTheme'><br>\";
  6. $handle=opendir('themes');
  7. while ($file = readdir($handle)) {
  8. if ( (!ereg(&#092;"[.]\",$file)) ) {
  9. $themelist .= &#092;"$file \";
  10. }
  11. }
  12. closedir($handle);
  13. $themelist = explode(&#092;" \", $themelist);
  14. sort($themelist);
  15. for ($i=0; $i < sizeof($themelist); $i++) {
  16. if($themelist[$i]!=&#092;"\") {
  17. echo &#092;"<option name='DefaultTheme' value='$themelist[$i]' \";
  18. if($themelist[$i]==$DefaultTheme) echo &#092;"selected\";
  19. echo &#092;">$themelist[$i]n\";
  20. }
  21. }
  22. echo &#092;"<center><input type='submit' value='Zapisz'></center></form>\";
  23. }
  24.  
  25. theme_set()
  26. ?>

Nie mogę poradzić sobie z wpisaniem tego w formularz i przeładowaniem. Help!
Ociu
  1. <?php
  2. function theme_set_form()
  3. {
  4. echo &#092;"<center><form action='set_theme.php' method='post'>\"
  5. .&#092;"<select name='DefaultTheme'><br />\";
  6. $handle=opendir('themes');
  7. while ($file = readdir($handle)) {
  8. if ( $file != '.' && $file != '..' && is_dir($file)) {
  9. echo &#092;"<option \".($file == $DefaultTheme) ? \"selected\" : \"\" .\" value=\".$file.\">\".$file.\"</option>\"; # wynikl blad, poprawiony
  10. }
  11. }
  12. closedir($handle);
  13.  
  14. echo &#092;"<center><input type='submit' value='Zapisz'></center></form>\";
  15. }
  16.  
  17. function set_theme($theme)
  18. {
  19. if($theme != null)
  20. {
  21. setcookie('theme', $theme, time()+60*60*24); # czy tam do bazy zapisujesz, jak wolisz
  22. }
  23. }
  24.  
  25. if(!isset($_COOKIE['theme']) OR empty($_POST['DefaultTheme']))
  26. {
  27. echo theme_set_form();
  28. } else {
  29. set_theme($_POST['DefaultTheme']);
  30. }
  31. ?>
Kshyhoo
Hmm, to nie działa sad.gif
Wolałbym przekazać do tego samego pliku...
Ociu
tzn. co nie działa ?

error_reporting(E_ALL); - na poczatku daj
Kshyhoo
Interesuje mnie ten fragment:
  1. <?php
  2. function theme_set_form()
  3. {
  4. echo &#092;"<center><form action='set_theme.php' method='post'>\"
  5. .&#092;"<select name='DefaultTheme'><br />\";
  6. ?>

Jak to zrobić w obrębie jednego pliki?
Ociu
$_SERVER['PHP_SELF'];
Guest
Chyba się poddam, nie mogę tego skręcić...
Ociu
  1. <?php
  2. function theme_set_form()
  3. {
  4. echo &#092;"<center><form action='\".$_SERVER['PHP_SELF'].\"' method='post'>\"
  5. .&#092;"<select name='DefaultTheme'><br />\";
  6. ?>


W poprzednim kodzie wynikl blad w lini 10, poprawilem
Kshyhoo
Wyświetla mi formularz wyboru ale bez listy folderów. Na tym kończy wyświetlanie. tzn, nie wyświetla np. stopki.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.