Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Walidacja pól
Largo
post
Post #1





Grupa: Zarejestrowani
Postów: 203
Pomógł: 6
Dołączył: 11.09.2005

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


Witam,

Mam oto taki skrypcik:

  1. <script type='text/javascript'>
  2. function checkFields()
  3. {
  4. var requiredFields = new Array ( 'game_name', 'game_pass', 'battle_acc', 'reason', 'tid' );
  5. var errors = "";
  6.  
  7. for ( var i = 0; i < requiredFields.length; i++ )
  8. {
  9. if ( requiredFields[i] == "" )
  10. {
  11. errors += '{$this->ipsclass->lang['required_fields']}';
  12. }
  13. }
  14.  
  15. if ( errors != "" )
  16. {
  17. alert( errors );
  18. return false;
  19. }
  20. return true;
  21. }


Ma on teoretycznie bardzo proste. Ma zdefiniowane pola "name", które są wymagane. Niestety, nie działa jak powinien, nic nie robi, FF nie wyrzuca błędów, nic... Jak to poprawić?
Go to the top of the page
+Quote Post
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




if ( requiredFields[i] == "" )

mala wskazowka:
przeciez pod requiredFields[i] masz tylko nazwe pola a nie pole (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
Largo
post
Post #3





Grupa: Zarejestrowani
Postów: 203
Pomógł: 6
Dołączył: 11.09.2005

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


Witaj,

Fakt, sprawdziłem i masz rację. Poprawiłem to tak, ale dalej nie działa:

  1. <script type='text/javascript'>
  2. function checkFields(form)
  3. {
  4. var requiredFields = new Array ( 'game_name', 'game_pass', 'battle_acc', 'reason', 'tid' );
  5. var errors = "";
  6.  
  7. for ( var i = 0; i < requiredFields.length; i++ )
  8. {
  9. if ( form.getElementsByName(requiredFields[i]).value == "" )
  10. {
  11. errors += '{$this->ipsclass->lang['required_fields']}';
  12. }
  13. }
  14.  
  15. if ( errors != "" )
  16. {
  17. alert( errors );
  18. return false;
  19. }
  20. return true;
  21. }
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




nie trzymaj tam nazwy tylko id.
poźniej do pola dobieraj sie poprzez document.getElementById()
no i dla pol nadaj jeszcze to id
Go to the top of the page
+Quote Post
Largo
post
Post #5





Grupa: Zarejestrowani
Postów: 203
Pomógł: 6
Dołączył: 11.09.2005

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


Witaj,

Dziękuje za pomysł. Wszystko dobrze mi teraz działa :-) Ale dlaczego ja o ID nie pomyślałem? :-) Chyba nauka JS mi się od samych podstaw kłania... Mimo to dziękuję.

Pozdrawiam,
Largo

PS. Mam kolejny, ale wyjątkowo dziwny problem! W pętli przejeżdzam po błędach i mam taki kod:

Kod
            alert ( 'Zmienna nazywa się: ' + requiredFieldsErrors[i] );
            errors += "{$this->ipsclass->lang['" + requiredFieldsErrors[i] + "']}\n";


Pierwsza linijka wykonuje się poprawnie ( Pokazuje: Zmienna nazywa się: XX ) i tak 4 razy i poprawne dane daje, a druga część nie. Tutaj chodzi o to, że w $this->ipsclass->lang[ ' ' ] Przekazuje się nazwę zmiennej ( 'no_game' ), tamten skrypt to pokazuje, a ten nie? Dlaczego?

Ten post edytował Largo 2.04.2009, 15:40:19
Go to the top of the page
+Quote Post
nospor
post
Post #6





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




co to jest:
{$this->ipsclass->lang
?
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: 4.10.2025 - 12:45