Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [jQuery] Walidacja formularza w "locie"
martinii007
post 19.06.2013, 09:52:31
Post #1





Grupa: Zarejestrowani
Postów: 80
Pomógł: 0
Dołączył: 15.12.2011

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


Witam,

W jaki sposób mogę zwalidować "checkbox'a" żeby również był walidowany w "locie" tak jak pozostała część formularza?

jQuery:


$("#form1").validate({

debug: true,
submitHandler: function(form) {

form.submit();
//alert("Mail gotowy do wysłania!");

},
errorElement: "div",
errorContainer: $("#warning, #summary"),
errorPlacement: function(error, element) {
error.appendTo( element.parent("td").next("td") );
},
success: function(label) {
label.addClass("validr").text("Dane wprowadzone poprawnie!")
},
messages: {

name: {
required: \'To pole jest obowiązkowe!\',
minlength: \'Podano mniej niż 3 znaki\'
},
mail: {
required: \'To pole jest obowiązkowe!\',
email: \'Podano nie prawidłowy adres e-mail\'
},
subject: {
required: \'To pole jest obowiązkowe!\',
minlength: \'Podano mniej niż 10 znaków\'
},
msg: {
required: \'To pole jest obowiązkowe!\',
minlength: \'Podano mniej niż 20 znaków\'
},
check: {
required: \'To pole jest obowiązkowe!\' //Tu jest problem

}
}
});
';

HTML:

  1. <form name="form" id="form" action="mail" method="POST">
  2.  
  3. <table class="objTable">
  4.  
  5. <tbody>
  6.  
  7. <tr><td id="formularz">Formularz kontaktowy</td><tr>
  8. <tr>
  9. <td>Imię i nazwisko:</td>
  10. <td><input type="text" value="" name="name" id="name" class="required" minlength="3" maxlength="20" tabindex="1" /></td>
  11. <td></td>
  12. </tr>
  13.  
  14. <tr>
  15. <td>Twój e-mail:</td>
  16. <td><input type="text" value="" name="mail" class="required email" tabindex="2" /></td>
  17. <td></td>
  18. </tr>
  19.  
  20. <tr>
  21. <td>Temat:</td>
  22. <td><input type="text" value="" name="subject" class="required" minlength="10" tabindex="3" /></td>
  23. <td></td>
  24. </tr>
  25.  
  26. <tr>
  27. <td>Wiadomość:</td>
  28. <td><textarea name="msg" class="required" minlength="20" tabindex="4"></textarea></td>
  29. <td></td>
  30. </tr>
  31.  
  32. <tr>
  33. <td><label for="sent-to-me" id="sent-to-me">Wyślij mi kopię tej wiadomości</label></td>
  34. <td><input type="checkbox" name="check" id="kontaktcheck" tabindex="5"/></td>
  35. <td></td>
  36. </tr>
  37.  
  38. </tbody>
  39.  
  40. </table>
  41.  
  42. <br /><br />
  43.  
  44. <input type="submit" name="submit-form" id="wyslij" value="" />
  45.  
  46. </form>
Go to the top of the page
+Quote Post
b4rt3kk
post 19.06.2013, 10:06:29
Post #2





Grupa: Zarejestrowani
Postów: 1 933
Pomógł: 460
Dołączył: 2.04.2010
Skąd: Lublin

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


  1. if ($('#kontaktcheck').is(':checked')) {
  2. // zaznaczony
  3. } else {
  4. // nie zaznaczony
  5. }


--------------------
Jeśli pomogłem, kliknij proszę 'pomógł'. Dzięki.
Go to the top of the page
+Quote Post
martinii007
post 19.06.2013, 10:45:00
Post #3





Grupa: Zarejestrowani
Postów: 80
Pomógł: 0
Dołączył: 15.12.2011

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


Niestety nie działa sad.gif
Jak wstawię powyższy skrypt to walidacja przestaje w ogóle działać.
Zapomniałem dodać, że waliduję za pomocą skryptu klik
Nie jestem specjalistą z jQuery, ale myślę, że powinno być coś w tym stylu jak napisałem wyżej:

check: {
required: \'To pole jest obowiązkowe!\' //Tu jest problem
}

Tyle, że mam chyba złą składnie.
Go to the top of the page
+Quote Post
b4rt3kk
post 19.06.2013, 10:53:00
Post #4





Grupa: Zarejestrowani
Postów: 1 933
Pomógł: 460
Dołączył: 2.04.2010
Skąd: Lublin

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


Nie znam wszystkich pluginów do jQuery. Ale wystarczyło doczytać dokumentację:

  1. rules: {
  2. 'check': {
  3. required: true,
  4. maxlength: 1
  5. }
  6. },
  7. messages: {
  8. 'check': {
  9. required: "Zaznacz checkbox"
  10. }
  11. }


--------------------
Jeśli pomogłem, kliknij proszę 'pomógł'. Dzięki.
Go to the top of the page
+Quote Post
martinii007
post 19.06.2013, 11:08:44
Post #5





Grupa: Zarejestrowani
Postów: 80
Pomógł: 0
Dołączył: 15.12.2011

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


Podziękował yahoo.gif
Można zamknąć

Ten post edytował martinii007 19.06.2013, 11:21:50
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 Wersja Lo-Fi Aktualny czas: 25.07.2025 - 08:00