I am sending a form via Ajax and have that part working fine.
 
Now my issue is if I use validate before sending I have to write the exact
validation rues that are done on the server...not the best solution coding
the same thing twice. And some of my validation rules require checking the
database for existing emails and other fields like that it gets a lot more
complicated with remote and all that scripting.
 
My problem is (will try to explain so it makes sense) I click "edit" button
on a page and a this does an Ajax requests to load a form into a div
allowing the user to make their edits, "save" then removes the form and
shows the updated content or "cancel" jut removes the form.

What I would like to do is skip validating the form with js all together,
but when it is submitted it just sits there until it gets a response from
the server saying "ok its all valid and saved" then remove the form and do
the toggle slide fades and jazzy stuff....if not saved then the errors
reported by the server show up.
 
I have currently:
 
$(form_id).bind('submit', function() {
  //$(this).validate(validate_domain);
//  var valid = $(this).valid();
//   if (valid) {
  var queryString = $(form_id).formSerialize();
 
  $(this).ajaxSubmit({
    //beforeSubmit: validate,
    type:    'post',
    url:      form_url',
    data:     queryString,
    target:   '#' + update_target,
    success: function(){
     $('#' + update_target).slideToggle('slow');
      $('#' + page_target).slideToggle('slow', function () {
      $(".success").show().fadeOut(5000).slideUp();
      });
     }
             });
   //}
    
 return false;
 });

I was thinking something like (im new at this so try not to laugh if im way
off)
$(this).ajaxSubmit({
    //beforeSubmit: validate,
    type:    'post',
    url:      form_url',
    data:     queryString,
    target:   '#' + update_target,
    success: valid_response


if (if valid_response) == valid)
{
//valid so do whatever I need to do
$('#' + update_target).slideToggle('slow');
      $('#' + page_target).slideToggle('slow', function () {
      $(".success").show().fadeOut(5000).slideUp();
      });



}else {

//do nothing, server will show errors on the form
}
 
Function validResponse(response){
var valid = false;
if (response = valid){
 valid =  true;
}
return valid;
}

Any help would be appreicated.

Thanks

Dave

Reply via email to