DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Validation and Submition scripts not working together

  1. #1
    Join Date
    Oct 2004
    Posts
    3

    Validation and Submition scripts not working together

    I am a beginner on Ajax and have found a ready made validation script that works perfectly.
    I have also managed to get an example of Ajax and PHP working so that the form submits the details and depending what the PHP page returns it will display "Message sent" or "Message failed to send".

    I am having trouble marrying these two examples together, currently I have something like this:

    Code:
    <script type="text/javascript">
    jQuery(document).ready(function(){
    	
    	$("#contactform").validationAideEnable(null, {showInlineMessages:true, showSummary:false});
    
    	$('#contactform').submit(function(){
     
    		var action = $(this).attr('action');
     
    		$('#submit')
    			.before('<img src="images/ajax-loader.gif" class="loader" />')
    			.attr('disabled','disabled');
     
    		$.post(action, { 
    			Your_Name: $('#Your_Name').val(),
    			E-mail_Address: $('#E-mail_Address').val(),
    			Phone_Number: $('#Phone_Number').val(),
    		},
    
    			function(data){
    				$('#contactform #submit').attr('disabled','');
    				$('.response').remove();
    				$('#contactform').before('<span class="response">'+data+'</span>');
    				$('.response').slideDown();
    				$('#contactform img.loader').fadeOut(500,function(){$(this).remove()});
    				if(data=='Message sent!') $('#contactform').slideUp();
    			}
    		);
     
    		return false;
     
    	});
     
    
    	
    });
    </script>
    I have my validation script
    Code:
    $("#contactform").validationAideEnable(null, {showInlineMessages:true, showSummary:false});
    Followed by my code that submits the data.
    The thing is when the data is invalid the validation script comes back saying there is an error yet it continues with the submission of the data anyway. Is there any way I can stop it from submitting data when there is some invalid input?

    Thanks

  2. #2
    Join Date
    Mar 2007
    Location
    Bangalore, India
    Posts
    247
    This script uses jQuery, which I'm not too good at.
    Is validationAideEnable() your validation script? Or is it something provided by jQuery?

    Basically, the script does validation, but still continues to send because the "submit" part is done unconditionally. It should be something like (if (validtaionIsOk()) submit(); )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center