Avatar of kbsad1
kbsad1Flag for United States of America asked on

Jquery submit form question

I have downloaded a step form in jquery that works perfect for me. The only part I am stuck with is the submission part. Here is the script:

<script>

    $('form.idealforms').idealforms({

      silentLoad: false,

      rules: {
        'email': 'required email',
        'password': 'required pass',
        'confirmpass': 'required equalto:password',
       
        'hobbies[]': 'minoption:2 maxoption:3',
        'phone': 'required phone',
        'zip': 'required zip',
        'options': 'select:default',
      },

      errors: {
        'username': {
          ajaxError: 'Username not available'
        }
      },

      onSubmit: function(invalid, e) {
        e.preventDefault();
        $('#invalid')
          .show()
          .toggleClass('valid', ! invalid)
          .text(invalid ? (invalid +' invalid fields') : 'All good!');
      }
    });



    $('form.idealforms').find('input, select, textarea').on('change keyup', function() {
      $('#invalid').hide();
    });

    $('form.idealforms').idealforms('addRules', {
      'comments': 'required minmax:50:200'
    });

    $('.prev').click(function(){
      $('.prev').show();
      $('form.idealforms').idealforms('prevStep');
    });
    $('.next').click(function(){
      $('.next').show();
      $('form.idealforms').idealforms('nextStep');
    });

  </script>

With this script when all requirements are met I get the message  'All good!'. But instead of that I want the form to be submitted.

The form tag is : <form action="untitled1.asp" method="post" class="idealforms" novalidate autocomplete="off">




How can I have it to submit the form?
Adobe DreamweaverjQueryJavaScript

Avatar of undefined
Last Comment
kbsad1

8/22/2022 - Mon
Scott Fell

https://api.jquery.com/submit/

.submit() can submit the form
$('form.idealforms').submit();

Open in new window


Just add that to your logic in your current jquery code where you want to submit.
ASKER
kbsad1

in this section:

onSubmit: function(invalid, e) {
        e.preventDefault();
        $('#invalid')
          .show()
          .toggleClass('valid', ! invalid)
          .text(invalid ? (invalid +' invalid fields') : 'All good!');

Where do you add that $('form.idealforms').submit(); ?
Scott Fell

I am not crazy about this, but the last line is a condition https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator

It reads like, If invalid, add invalid code else write out, "All good".  So in place of 'All Good!'
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Scott Fell

I gave you wrong advice.  Are you useing https://github.com/elclanrs/jq-idealforms#methods

Just use isValid and then submit the form
ASKER
kbsad1

Scott Fell

I just did a test with your code.

onSubmit: function(invalid, e) {
        e.preventDefault();
        $('#invalid')
          .show()
          .toggleClass('valid', ! invalid)
          .text(invalid ? (invalid +' invalid fields') : 'All good!');
        
        if(!invalid){
         $('form.idealforms').submit();
        }
      }

Open in new window


Also, from their code
$('form').idealforms({
  onSubmit: function(invalid, e) {
    e.preventDefault();

    if (invalid) {
      alert(invalid +' fields!');
    } else {
      $.post('save.php', this.$form.serialize(), function(response) {  
        // do something with response
      }, 'json');
    }    
  }
});

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Scott Fell

The link I gave you is the actual source
ASKER CERTIFIED SOLUTION
kbsad1

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Scott Fell

Like any of this, there are going to be multiple ways to the same end.  If it works... do it.
ASKER
kbsad1

Used comments and ideas from Scott Fell.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes