Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Sprawdzanie fomularza - wyrażenia reg PCRE
aleo
post
Post #1





Grupa: Zarejestrowani
Postów: 137
Pomógł: 0
Dołączył: 23.08.2008

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


  1. <form action="" method=get >
  2.  <input type="text" name="mail">
  3.  <input type="submit" value="send"></form>
  4.  
  5.  <?php
  6.  
  7.  
  8.  
  9.  if (isset($_GET['send'])) {
  10.      if ( preg_match("/w+@.w{2,4}/" . $_GET['send']=! 1 ) ) {
  11.          echo"dobrze" ;
  12.      }
  13.      else "zle";
  14.  }
  15.  
  16.  
  17.  ?>


Witam

Dlaczego powyższy fomularz nie działa ?
Go to the top of the page
+Quote Post
Spawnm
post
Post #2





Grupa: Moderatorzy
Postów: 4 069
Pomógł: 497
Dołączył: 11.05.2007
Skąd: Warszawa




send to value a nie name
Go to the top of the page
+Quote Post
RubiX
post
Post #3





Grupa: Zarejestrowani
Postów: 162
Pomógł: 6
Dołączył: 14.02.2007
Skąd: Poznań

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


  1. <?php
  2. if ( preg_match("/w+@.w{2,4}/" . $_GET['mail'])=! 1 ) {
  3. ?>


Ten post edytował RubiX 9.04.2009, 12:08:50
Go to the top of the page
+Quote Post
aleo
post
Post #4





Grupa: Zarejestrowani
Postów: 137
Pomógł: 0
Dołączył: 23.08.2008

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


ok ale skrypt mi nadal nie dziala co jest zle
  1. <?php
  2.  
  3.  
  4.  
  5.  if (isset($_GET['send'])) {
  6.      if ( preg_match("/w+@.w{2,4}/" , $_GET['send']) !=1 )  {
  7.          echo"zle" ;
  8.      } }
  9.      else  { echo "dobrze";
  10.  }
  11.  
  12.  
  13.  ?>
Go to the top of the page
+Quote Post
RubiX
post
Post #5





Grupa: Zarejestrowani
Postów: 162
Pomógł: 6
Dołączył: 14.02.2007
Skąd: Poznań

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


Zamień SEND na MAIL (IMG:http://forum.php.pl/style_emoticons/default/exclamation.gif)

  1. <?php
  2. if (isset($_GET['mail'])) {
  3.     if ( preg_match("/w+@.w{2,4}/" , $_GET['mail']) !=1 )  {
  4.         echo"zle" ;
  5.     } }
  6.     else  { echo "dobrze";
  7. }
  8. ?>
Go to the top of the page
+Quote Post
aleo
post
Post #6





Grupa: Zarejestrowani
Postów: 137
Pomógł: 0
Dołączył: 23.08.2008

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


zrobiłem tak ale nadal źle
  1. <form action="" method=get >
  2.      <input type ="hidden" name="phon" value="1">
  3.  <input type="text" name="mail">
  4.  <input type="submit" value="send"
  5.  name="send"></form>
  6.  
  7.  <?php
  8.  
  9.  
  10.  
  11.  if (isset($_GET['phon'])) {
  12.      if ( preg_match("/w+@.w{2,4}/" , $_GET['mail']) !=1 )  {
  13.          echo"zle" ;
  14.      } }
  15.      else  { echo "dobrze";
  16.  }
  17.  
  18.  
  19.  ?>
Go to the top of the page
+Quote Post
slawny
post
Post #7





Grupa: Zarejestrowani
Postów: 214
Pomógł: 26
Dołączył: 7.11.2007
Skąd: Warszawa

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


  1. <?php
  2. if(!eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$",$_GET['mail'])
  3.   {
  4.       echo "Podany email nie jest prawidłowy.";
  5.   }
  6. ?>
Go to the top of the page
+Quote Post
wookieb
post
Post #8





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




@slawny Nie no stary tym ostatnim to padłes na całej liniii Eregi się używa.

@aleo zrób sobie na odwrot
Kod
if(preg_match("/\w+@\.\w{2,4}/" , $_GET['mail']))
{
echo 'ok';
}
else echo 'nie';

A potem powiedz jaki mail wpisałes.
I jeszcze wyświetl sobie tablice $_GET
Kod
print_r($_GET);


Ten post edytował wookieb 9.04.2009, 12:41:51
Go to the top of the page
+Quote Post
slawny
post
Post #9





Grupa: Zarejestrowani
Postów: 214
Pomógł: 26
Dołączył: 7.11.2007
Skąd: Warszawa

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


Cytat(wookieb @ 9.04.2009, 13:38:02 ) *
@slawny Nie no stary tym ostatnim to padłes na ostatniej liniii Eregi się używa.


co tym razem odstawiłem nie tak?
Go to the top of the page
+Quote Post
aleo
post
Post #10





Grupa: Zarejestrowani
Postów: 137
Pomógł: 0
Dołączył: 23.08.2008

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


no nadal nie działa

nieArray ( [mail] => forumphp@wp.pl [send] => send )
Go to the top of the page
+Quote Post
wookieb
post
Post #11





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Dopiero teraz to zauwazyłem
Użyj wyrazenia (pierwszy argument funkcji) od @slawny (zamien eregi na preg_match i wstaw / / na poczatku i koncu wyrazenia)

Ten post edytował wookieb 9.04.2009, 12:49:16
Go to the top of the page
+Quote Post
aleo
post
Post #12





Grupa: Zarejestrowani
Postów: 137
Pomógł: 0
Dołączył: 23.08.2008

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


pogubiłem się (IMG:http://forum.php.pl/style_emoticons/default/sciana.gif)

kod
  1. <?php
  2.  
  3.  
  4.  
  5.  
  6. if(preg_match("//^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$//",$_GET['mail']))
  7. {
  8. echo 'ok';
  9. }
  10. else echo 'nie<BR>';
  11. print_r($_GET);
  12.  ?>
  13.    </body>
  14. </html>



O to chodziło ?

na dodatek wyskoczył error Warning: preg_match() [function.preg-match]: Unknown modifier '[' in /home/desk/public_html/php/ke/listing_5/listing_5_5.php on line 23 (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Nie wiem gdzie mam umiescic te //
Go to the top of the page
+Quote Post
wookieb
post
Post #13





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Ech :/ faktycznie źle się wyraziłem. Przepraszam i Proszę:
Kod
if(preg_match("/^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/",$_GET['mail']))


Ten post edytował wookieb 9.04.2009, 12:59:20
Go to the top of the page
+Quote Post
erix
post
Post #14





Grupa: Moderatorzy
Postów: 15 467
Pomógł: 1451
Dołączył: 25.04.2005
Skąd: Szczebrzeszyn/Rzeszów




preg_quote" title="Zobacz w manualu PHP" target="_manual i zobacz, co będziesz musiał escape'ować. (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
Go to the top of the page
+Quote Post
aleo
post
Post #15





Grupa: Zarejestrowani
Postów: 137
Pomógł: 0
Dołączył: 23.08.2008

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


ok dzięki koledzy proszę jednak o jeszcze jedno wytłumaczenie kod
  1. <form action="" method=get >
  2.     <input type ="hidden" name="phon" value="1">
  3. <input type="text" name="mail">
  4. <input type="text" name="mail2">
  5. <input type="submit" value="send"
  6. name="send"></form>
  7.  
  8.  <?php
  9.  
  10.  
  11.  
  12.  
  13. if((preg_match("/^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/",$_GET['mail'] )) && (preg_match("/^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/",$_GET['mail2'] )) )
  14. {
  15. echo 'ok';
  16. }
  17. else echo 'nie<BR>';
  18. print_r($_GET);
  19.  ?>


Notice: Undefined index: mail in /home/desk/public_html/php/ke/listing_5/listing_5_5.php on line 24

Dlaczego wyskakuje ten błąd ? Przecież jest mail ?

Proszę o wytłumaczenie .
Go to the top of the page
+Quote Post
wookieb
post
Post #16





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




nie ma go dopkoi nie wyslales formularza. Dlatego robi sie na poczatku
  1. <?php
  2. if(isset($_GET['mail']))
  3. ?>


Ten post edytował wookieb 9.04.2009, 13:31:37
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: 18.09.2025 - 01:20