zacząłem bawić się jQuery. Znalazłem w sieci skrypt sprawdzający pola:
http://roshanbh.com.np/2008/04/check-usern...php-jquery.html
chciałem go trochę przerobić:
<script language="javascript"> $(document).ready(function() { $("#username").blur(function() { //remove all the class add the messagebox classes and start fading $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow"); //check the username exists or not from ajax $.post("user_availability.php?co=acc",{ user_name:$(this).val() } ,function(data) { if(data=='no') //if username not avaiable { $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox { //add message and change the class of the box and start fading $(this).html('This User name Already exists').addClass('messageboxerror').fadeTo(900,1); }); } else { $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox { //add message and change the class of the box and start fading $(this).html('Username available to register').addClass('messageboxok').fadeTo(900,1); }); } }); }); }); </script>
główna "przeróbka" to:
$.post("user_availability.php?co=acc",{ user_name:$(this).val() } ,function(data)
oraz:
switch ($_GET['co']) { case 'acc': //value got from the get metho $user_name=$_POST['user_name']; //checking weather user exists or not in $existing_users array { //user name is not availble } else { //user name is available } break; }
czyli dodanie switcha, niestety po tym co zrobiłem skrypt przestał działać, switcha dodałem w celu "zautomatyzowania" skryptu (żebym później nie musiał tworzyć osobnych plików .js i .php do sprawdzania). Wiem że problem jest w przekazywaniu zmiennej czyli $user_name=$_POST['user_name'];, po prostu nie czyta tego co się wpisało tylko cały czas pisze że można zarejestrować pomimo tego że wpisze się mike ect.
Proszę o pomoc.