Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem ze smarty, tym razem formularze
Legro
post
Post #1





Grupa: Zarejestrowani
Postów: 233
Pomógł: 3
Dołączył: 18.07.2005

Ostrzeżenie: (40%)
XX---


Mam taki skrypt w php do logowania admina:

  1. <?php
  2.  
  3. require_once ('../config.php');
  4.  
  5. if ( !empty ( $_POST['login'] ) && !empty ( $_POST['haslo'] )) {
  6.  
  7. foreach ( $admins as $l => $h ) {
  8.  
  9. if ( $l == $_POST['login'] ) {
  10.  
  11. if ( $h == $_POST['haslo'] ) {
  12.  
  13. $_SESSION['Admin'] = $_POST['login'];
  14. }
  15.  }
  16. }
  17.  }
  18.  
  19.  
  20. if ( ! $_SESSION['Admin'] ) {
  21.  
  22. echo '<form action="index.php" method="post">';
  23. echo '<input type="text" name="login"><br />';
  24. echo '<input type="password" name="haslo"><br />';
  25. echo '<input type="submit">';
  26. echo '</form>';
  27.  
  28. } else {
  29.  
  30. header ("Location: admin.php");
  31.  
  32. }
  33.  
  34. ?>


Przerobilem go sobie na smarty:

  1. <?php
  2.  
  3. require_once ('../config.php');
  4. require_once ( SMARTY_DIR . 'Smarty.class.php' );
  5.  
  6. if ( !empty ( $_POST['login'] ) && !empty ( $_POST['haslo'] )) {
  7.  
  8. foreach ( $admins as $l => $h ) {
  9.  
  10. if ( $l == $_POST['login'] ) {
  11.  
  12. if ( $h == $_POST['haslo'] ) {
  13.  
  14. $_SESSION['Admin'] = $_POST['login'];
  15. }
  16.  }
  17. }
  18.  }
  19.  
  20. /******* TUTTAJ *******/
  21.  
  22.  
  23. if ( ! $_SESSION['Admin'] ) {
  24.  
  25. echo '<form action="index.php" method="post">';
  26. echo '<input type="text" name="login"><br />';
  27. echo '<input type="password" name="haslo"><br />';
  28. echo '<input type="submit">';
  29. echo '</form>';
  30.  
  31. } else {
  32.  
  33. header ("Location: admin.php");
  34.  
  35. }
  36.  
  37. $smarty->display('adm_login.tpl');
  38.  
  39. ?>


ale teraz mam problem z formularzem.

jak zrobic aby go nie bylo w kodzie php tylko zeby byl w tpl ?
jak go przeniose do pliku adm_login.tpl to nie dziala formularz.

w drugim kodzie od linijki /******* TUTTAJ *******/ jest takie cos:

- jezeli zmienna $_SESSION['Admin'] nie istnieje, wyswietlamy formularz, a jezeli istnieje to przekierowyje do pliku admin.php

jak to zrobic w smartach??

pozdrawiam, juz sie mecze z tym od tego czasu jak skonczylem na konfiguracji sciezek do smarty winksmiley.jpg

Ten post edytował Legro 12.05.2006, 21:49:58


--------------------
nospor - jestem z Wami !!!
Go to the top of the page
+Quote Post
ikioloak
post
Post #2





Grupa: Zarejestrowani
Postów: 416
Pomógł: 0
Dołączył: 8.01.2004

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


Cytat(Legro)
jak go przeniose do pliku adm_login.tpl to nie dziala formularz.

Co to znaczy niedziala? Co sie dzieje?
Go to the top of the page
+Quote Post
Legro
post
Post #3





Grupa: Zarejestrowani
Postów: 233
Pomógł: 3
Dołączył: 18.07.2005

Ostrzeżenie: (40%)
XX---


Nie dziala, tz. ze wpisuje poprawne dane a skrypt sie nie loguje :/

------------ EDIT

Nie, powiem tak:

mam ten kod:

  1. <?php
  2.  
  3. require_once ('../config.php');
  4. require_once ( SMARTY_DIR . 'Smarty.class.php' );
  5.  
  6. if ( !empty ( $_POST['login'] ) && !empty ( $_POST['haslo'] )) {
  7.  
  8. foreach ( $admins as $l => $h ) {
  9.  
  10. if ( $l == $_POST['login'] ) {
  11.  
  12. if ( $h == $_POST['haslo'] ) {
  13.  
  14. $_SESSION['Admin'] = $_POST['login'];
  15. }
  16.  }
  17. }
  18.  }
  19.  
  20. /******* TUTTAJ *******/
  21.  
  22.  
  23. if ( ! $_SESSION['Admin'] ) {
  24.  
  25. echo '<form action="index.php" method="post">';
  26. echo '<input type="text" name="login"><br />';
  27. echo '<input type="password" name="haslo"><br />';
  28. echo '<input type="submit">';
  29. echo '</form>';
  30.  
  31. } else {
  32.  
  33. header ("Location: admin.php");
  34.  
  35. }
  36.  
  37. $smarty->display('adm_login.tpl');
  38.  
  39. ?>


usuwam z tego kodu formularz i ten formularz przenosze do pliku tpl i dodaje value= i tu daje ze smarty ten kod smarty.post.costam np.

i co mam dac zamiast tego formularza w pliku php?

$smarty -> assign (co dac tu..);

zeby ten formularz dzialal :/

Ten post edytował Legro 13.05.2006, 20:20:02


--------------------
nospor - jestem z Wami !!!
Go to the top of the page
+Quote Post
anopak
post
Post #4





Grupa: Zarejestrowani
Postów: 124
Pomógł: 0
Dołączył: 26.10.2004
Skąd: Rybnik

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


plik php....
  1. <?php
  2. require_once ('../config.php');
  3. require_once ( SMARTY_DIR . 'Smarty.class.php' );
  4.  
  5. if ( !empty ( $_POST['login'] ) && !empty ( $_POST['haslo'] )) {
  6.  
  7. foreach ( $admins as $l => $h ) {
  8.  
  9. if ( $l == $_POST['login'] ) {
  10.  
  11. if ( $h == $_POST['haslo'] ) {
  12.  
  13. $_SESSION['Admin'] = $_POST['login'];
  14. }
  15.  }
  16. }
  17.  }
  18.  
  19. /******* TUTTAJ *******/
  20.  
  21.  
  22. if ( ! $_SESSION['Admin'] ) {
  23. $smarty->display('adm_login.tpl');
  24. } else {
  25. header ("Location: admin.php");
  26. }
  27. ?>


adm_login.tpl
  1. <form action="index.php" method="post">
  2. <input type="text" name="login" value="{$smarty.post.login}"><br />
  3. <input type="password" name="haslo"><br />
  4. <input type="submit">
  5. </form>


--------------------
Hardware: Celeron 3.06, 512 MB DDR
Software: Apache 2.0, MySQL 4.0, php 4.3.1, Zend 5.1, Firefox
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 Aktualny czas: 21.08.2025 - 06:58