Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php][jquery][validation] problem z walidacja formularzy
Forum PHP.pl > Forum > Przedszkole
ulotna_chwila87
Witam, jestem początkująca jeśli chodzi o jave script, php i w ogóle programowanie w internecie. Ostatnio męczę się nad biblioteką jquery.validation

Mianowicie mam formularz rejestracyjny (na stronie przykład mój) www.amehobpoezja.pl i nie mam pojęcia jak zrobić ta walidacje. Działa mi ta podstawowa gdy dam:

  1. $(document).ready(function() {
  2. $("#registerUser").validate();
  3. });
  4.  


w deklaracji strony mam:
  1. <script type="text/javascript" src="<?=url::base()?>js/jquery.validate.js"></script>
  2. <script type="text/javascript" src="<?=url::base()?>js/jquery-1.3.2.min.js"></script>


a formukarz wygląda tak:
  1. <form name="registerUser" id="registerUser" action="<?=url::base(true)?>user/rejestruj" method="post">
  2. <div class="left">
  3. <h1>Nie masz profilu? Zarejestruj się </h1>
  4.  
  5. <label class="grey" for="email_rej">Email:</label>
  6. <em>* </em><input class="field wpisz email required" type="text" name="email_rej" id="email_rej" value=""/>
  7.  
  8. <label class="grey" for="haslo_rej">Hasło:</label>
  9. <em>* </em><input class="field wpisz" type="password" name="haslo_rej" id="haslo_rej"/>
  10.  
  11. <label class="grey" for="powt_haslo_rej">Powtórz hasło:</label>
  12. <em>* </em><input class="field wpisz" type="password" name="powt_haslo_rej" id="powt_haslo_rej" size="20" />
  13.  
  14. <label class="grey" for="login_rej">Nick:</label>
  15. <em>* </em><input class="field wpisz" type="text" name="login_rej" id="login_rej" size="20" value=""/>
  16.  
  17. <label class="grey" for="plec_rej">Płeć:</label>
  18. <em>* </em><select id="plec_rej" name="plec_rej" class="field plec">
  19. <option value="0" selected="selected">wybierz</option>
  20. <option value="1">kobieta</option>
  21. <option value="2">mężczyzna</option>
  22. </select> <img src="../images/info2.gif" alt="">
  23.  
  24. <label class="grey" for="birthday_day_rej">Data urodzenia:</label>
  25. <em>* </em><select id="birthday_day_rej" name="birthday_day_rej" class="dataurdz field">
  26. <option value="-1">Dzień:</option>
  27. <?for( $birthday_day=1; $birthday_day<=31; $birthday_day++): ?>
  28. <option value="<?=$birthday_day?>"> <?=$birthday_day?> </option>
  29. <?endfor?>
  30. </select>
  31.  
  32. <em>* </em><select id="birthday_month_rej" name="birthday_month_rej" class="dataurm field" onchange=''>
  33. <option value="-1">Miesiąc:</option>
  34. <option value="1">stycznia</option>
  35. <option value="2">lutego</option>
  36. <option value="3">marca</option>
  37. <option value="4">kwietnia</option>
  38. <option value="5">maja</option>
  39. <option value="6">czerwca</option>
  40. <option value="7">lipca</option>
  41. <option value="8">sierpnia</option>
  42. <option value="9">września</option>
  43. <option value="10">października</option>
  44. <option value="11">listopada</option>
  45. <option value="12">grudnia</option>
  46. </select>
  47.  
  48. <em>* </em><select name="birthday_year_rej" id="birthday_year_rej" class="dataurr field">
  49. <option value="-1">Rok:</option>
  50. <?for( $birthday_year=2005; $birthday_year>=1900; $birthday_year--): ?>
  51. <option value="<?=$birthday_year?>"> <?=$birthday_year?> </option>
  52. <?endfor?>
  53. </select>
  54. </div>
  55.  
  56. <div class="left right">
  57. <label class="grey" for="kod">Przepisz poniższy kod:</label>
  58. <?=$kod?>
  59. <input class="field wpiszkod" type="text" name="kod" id="kod" value="222sa" size="20" />
  60. <div><label for="reg"><em>* </em><input id="reg" name="reg" value="tak" type="checkbox">
  61. - Oświadczam, iż zapoznałem się z <a href="#">regulaminem serwisu amehobpoezja.pl</a>, który akceptuję i będę przestrzegał.</label></div>
  62. <label for="dane">
  63. <em>* </em><input id="dane" name="dane" value="tak" type="checkbox">
  64. - Niniejszym oświadczam, że wyrażam zgodę na przetwarzanie moich danych osobowych
  65. w celu przeprowadzenia procesu nawiązania współpracy (zgodnie z Ustawą z dnia
  66. 29.08.1997r. o Ochronie Danych Osobowych Dz. U. Nr 133, poz. 883).</label>
  67. <input type="submit" name="submit" value="Rejestruj" class="bt_register" />
  68. </div>
  69. </form>
  70.  


nie mam pojęcia czemu jak wpiszę:
  1. $(document).ready(function() {
  2. $("#registerUser").validate();
  3. rules: {
  4. email_rej: {
  5. required: true,
  6. email: true
  7. },
  8. messages: {
  9. email_rej: {
  10. required: "Please enter a valid email address",
  11. minlength: "Please enter a valid email address"
  12. }
  13. });
  14.  


to już mi się nie waliduje sad.gif

gdzie robię błąd?

no i nie wiem jak się blokuje submit puki nie będą dobrze wypełnione wszystkie pola. Proszę Was o pomoc sad.gif

nie śmiejcie się ze mnie ;/ ps. w googleach niby są tutki ale nie działa mi to jak powinno. gdzieś robię błąd:(


pomyliłam działy i umieściłam tego posta też w dziale AJAX (proszę o usunięcie go, oraz przepraszam za kłopot)
lord_t
Zobacz poniższy kod i przyjrzyj się gdzie jest rules:{}:
Kod
$(document).ready(function() {
    // validate signup form on keyup and submit
    var validator = $("#signupform").validate({
        rules: {
            firstname: "required",
            lastname: "required",
            username: {
                required: true,
                minlength: 2,
                remote: "users.php"
            },
            password: {
                required: true,
                minlength: 5
            },
            password_confirm: {
                required: true,
                minlength: 5,
                equalTo: "#password"
            },
            email: {
                required: true,
                email: true,
                remote: "emails.php"
            },
            dateformat: "required",
            terms: "required"
        },
        messages: {
            firstname: "Enter your firstname",
            lastname: "Enter your lastname",
            username: {
                required: "Enter a username",
                minlength: jQuery.format("Enter at least {0} characters"),
                remote: jQuery.format("{0} is already in use")
            },
            password: {
                required: "Provide a password",
                rangelength: jQuery.format("Enter at least {0} characters")
            },
            password_confirm: {
                required: "Repeat your password",
                minlength: jQuery.format("Enter at least {0} characters"),
                equalTo: "Enter the same password as above"
            },
            email: {
                required: "Please enter a valid email address",
                minlength: "Please enter a valid email address",
                remote: jQuery.format("{0} is already in use")
            },
            dateformat: "Choose your preferred dateformat",
            terms: " "
        },
        // the errorPlacement has to take the table layout into account
        errorPlacement: function(error, element) {
            if ( element.is(":radio") )
                error.appendTo( element.parent().next().next() );
            else if ( element.is(":checkbox") )
                error.appendTo ( element.next() );
            else
                error.appendTo( element.parent().next() );
        },
        // specifying a submitHandler prevents the default submit, good for the demo
        submitHandler: function() {
            alert("submitted!");
        },
        // set this class to error-labels to indicate valid fields
        success: function(label) {
            // set &nbsp; as text for IE
            label.html("&nbsp;").addClass("checked");
        }
    });


P.S. Błąd masz w 2. linijce.
ulotna_chwila87
no ale w dallszym ciagu nie wyświetlają mi się
"messages"

  1. $(document).ready(function() {
  2.  
  3. $("#loginUser").validate({
  4. rules: {
  5. email_log: {
  6. required: true,
  7. email: true
  8. },
  9. haslo_log: {
  10. required: true
  11. },
  12. },
  13. messages: {
  14. email_log: {
  15. required: "Wymagane"
  16. },
  17. haslo_log: {
  18. required: "Wymagane"
  19. },
  20. },
  21. });
  22.  
  23. });


pokazują mi się te standardowe teksty a nie te które ja chce i tutaj je zadeklarowałam

a podczas naciskania submite mi się to wysyła mimo że nie są wypełnione pola
lord_t
W 20. linii masz przecinek po nawiasie klamrowym. Usuń go.
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.