The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Aug 16, 2012 1:34 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Mar 17, 2012 5:55 pm
Posts: 9
I am developing a Joomla component, and i got to the point where I need to validate the fields from my form.

I have followed this tutorial, I know it it for Joomla 1.5 but I still prefer this method and it works but I still have a problem. http://docs.joomla.org/Client-side_form_validation

This is my javascript validate function, which is only executed when the form is submitted with the task save.
Code:
<script language="javascript">
        function myValidate(f) {
           if($('#task').val() == "save"){
            if (document.formvalidator.isValid(f)) {
               f.check.value='<?php echo JUtility::getToken(); ?>'; //send token
               return true;
            }
            else {
               var msg = 'O valor dos seguintes campos é inválido:';

               //Example on how to test specific fields
               if($('#email_institucional').hasClass('invalid')){msg += '\n\n\t* Email Institucional';}
               if($('#email_alternativo').hasClass('invalid')){msg += '\n\n\t* Email alternativo';}

               alert(msg);
              //AVOID FORM FROM SUBMITTING CODE HERE

            }
         }
         return false;
      }
           
    </script>


The javascript function is executed "onSubmit", my problem is I need to stop the form from submiting when the form validator is not valid, I've checked on the web and everyone says I only need that function to return false, but in Joomla even with return false the form is submitted =/

Any thoughts on this? Thanks in advance :)


Top
 Profile  
 
PostPosted: Thu Aug 16, 2012 3:45 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Sat Dec 06, 2008 7:07 pm
Posts: 281
Did you put this in your form?
onSubmit="return myValidate(this);"

_________________
http://www.ratmilwebsolutions.com


Top
 Profile  
 
PostPosted: Thu Aug 16, 2012 4:24 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Mar 17, 2012 5:55 pm
Posts: 9
Ratmil wrote:
Did you put this in your form?
onSubmit="return myValidate(this);"


This is my code
Code:
<form onSubmit="return myValidate(this);" action="index.php" method="post" class="form-validate"  name="adminForm" id="adminForm">


But it's still submiting the form... =/

Thanks for the answer!


Top
 Profile  
 
PostPosted: Thu Aug 16, 2012 4:46 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Sat Dec 06, 2008 7:07 pm
Posts: 281
Then check if Javascript is disabled. If it is not then check for any javascript errors.

_________________
http://www.ratmilwebsolutions.com


Top
 Profile  
 
PostPosted: Thu Aug 16, 2012 5:13 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Sat Sep 23, 2006 5:54 am
Posts: 108
Here's the info you need for Joomla 2.5

http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Adding_verifications#Verifying_the_form_.28client_side.29


Top
 Profile  
 
PostPosted: Thu Aug 16, 2012 8:09 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Mar 17, 2012 5:55 pm
Posts: 9
Ratmil wrote:
Then check if Javascript is disabled. If it is not then check for any javascript errors.


Javascript is enabled, no errors in console.

NFG wrote:


Well I know but I don't want to use that method, I don't want to validate the forms via XML files...

The script is working, when the fields have invalid values, the class "invalid" is added to them but then, instead of no action, the form is still submitted...

Thanks for all the answers :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 



Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group