Crate a true or false for submit on form

Basically I am trying to create a JQuery script that would return true or false when a submit button on a form is clicked. so basically in this case if the form is not completed and the person clicks the submit form they receive the following text message. (“There was a problem with your submission. Errors have been highlighted below.”)

The URL is http://atlanticbay.com/amieecarr/. The form and submit button is at bottom of page.

Please review code on site page. HTML to long to post here.

Here is the JQuery script I tried.

$('.gform_footer').click(function() {
  var gForm = $(this).parents(':contains("There was a problem with your submission. Errors have been highlighted below.")');
  
  if (gForm.length) {
    // Do something here
  	return true;
 
  } else {
    // Don't follow the link
    return false;
  }
});

I am using this as a part of a custom script for Adobe Analytics to capture the event when a visitor submit a form. What I really want is to capture when it is a completed form, the message above comes when its submitted but the form is not complete. so I figure I could make adjustment to code once I am able to capture the event as true when the form is incomplete.

You could set the input elements to required within the HTML, so that it’s not possible to submit an incomplete form in the first place; like

<input type="text" required/>

You could still display a custom message like e.g.

$('input[type="submit"]').click(function() {
  if ($(this).closest('form').find('input:invalid').length) {
    
    // Do something
  }
})

Other than that, you might return false right within the form submit handler where the validation takes place (in jQuery that would be equivalent to event.preventDefault()), rather than additionally checking if that message has been displayed.

I cannot make changes to the HTML. I am only able to write scripts through the Adobe Analytics platform (DTM). So my solution set must be accomplished through Javascript or JQuery etc.

I will trying something like

$('input[type="submit"]').click(function() {
  if ($(this).closest('form').find('input:invalid').length) {
    
    // Do something
  }
})

Thanks for your input, I will keep you posted @m3g4p0p.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.