Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8536069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:34:37+00:00 2026-06-11T10:34:37+00:00

I have a form within a modal that i am trying to validate before

  • 0

I have a form within a modal that i am trying to validate before the form gets submitted to ajax db etc.

I am trying to validate the form $(“#new_request_form”).validate({ on the save button. if it validate then submit the form.

Can anybody tell me what i am missing?

Thanks in advance!

$(document).ready(dialogForms);
function dialogForms() {    
 $('a.menubutton').click(function() {
    var a = $(this);
    $.get(a.attr('href'),function(resp){
      var dialog = $('<div>').attr('id','formDialog').html($(resp).find('form:first').parent('div').html());
      $('body').append(dialog);
      dialog.find(':submit').hide();
      dialog.dialog({
        title: a.attr('title') ? a.attr('title') : '',
        modal: true,
        buttons: {
          'Save': function() {
                $("#new_request_form").validate({
                 submitHandler: function(form) {
                     submitFormWithAjax($(this).find('form'));
                    $(this).dialog('close');
                 }
                });

                },
          'Cancel': function() {$(this).dialog('close');}
        },
        close: function() {$(this).remove();},
        width: 600,
        height: 500,        
        show: "fade",
        hide: "fade"
      });

var $ac_start_date = '<?php echo $ac_end_date ?>',
    $ac_start_date_flip = '<?php echo $ac_end_date_flip ?>',
    $ac_start_parsed = Date.parse($ac_start_date),
    _today = new Date().getTime();

// For Opera and older winXP IE n such
if (isNaN($ac_start_parsed)) { 
    $ac_start_parsed  = Date.parse($ac_start_date_flip);
}

var _aDayinMS = 1000 * 60 * 60 * 24; 

// Calculate the difference in milliseconds
var difference_ms = Math.abs($ac_start_parsed - _today);

// Convert back to days and return
var DAY_DIFFERENCE = Math.round(difference_ms/_aDayinMS);       

// do initialization here
$("#startdate").datepicker({
            dateFormat: 'dd-mm-yy',
            changeMonth: true,
            changeYear: true,
            yearRange: '0:+100',
            minDate: '+1d',         
            maxDate: '+' + (DAY_DIFFERENCE + 1) + 'd'
});

// do initialization here
$("#enddate").datepicker({
            dateFormat: 'dd-mm-yy',
            changeMonth: true,
            changeYear: true,
            yearRange: '0:+100',
            minDate: '+1d',         
            maxDate: '+' + (DAY_DIFFERENCE + 1) + 'd'
});

}, 'html');
return false;
});
}

function submitFormWithAjax(form) {
  form = $(form);
  $.ajax({
    url: form.attr('action'),
    data: form.serialize(),
    type: (form.attr('method')),
    dataType: 'script',
    success: function(data){
    $(this).dialog('close');
    // Refresh table
   }
  });
  return false;
}

FORM

<?php
require_once("../config.php");
include_once("scripts/connection.php");
?>

<p class="validateTips">All form fields are required.</p>
<div>
<form id="new_request_form" action="insert_new_request.php" method="POST" class="new_request">
<fieldset>
   <legend><p class="subheadertext">Request Holiday</p></legend>

<table width="100%" border="0">

<?php
$username = $USER->firstname.' '.$USER->lastname;

$is_academic_result = mysql_query('SELECT * FROM holiday_entitlement_academic WHERE employee = \'' . $username . '\'');

if($is_academic = mysql_fetch_array($is_academic_result)) {
    switch($is_academic['units']) {
        case 'days':
                  echo'<tr>
                    <td width="150px" valign="middle"><label for="days">Days:</label></td>
                    <td valign="top">
                    <select id="days" name="days">
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    </select>
                    </td>
                  </tr>
                    <tr>
                      <td width="150px" valign="middle"><label for="startdate">Start Date:</label></td>
                      <td valign="top"><input type="text" name="startdate" id="startdate" class="required" readonly="readonly"/></td>
                    </tr>';
            break;
        case 'hours':
                  echo'<tr>
                    <td width="150px" valign="middle"><label for="days">Hours:</label></td>
                    <td valign="top"><input type="text" name="hours" id="hours" class="required" /></td>
                  </tr>
                    <tr>
                      <td width="150px" valign="middle"><label for="startdate">Start Date:</label></td>
                      <td valign="top"><input type="text" name="startdate" id="startdate" class="required" readonly="readonly"/></td>
                    </tr>
                    <tr>
                      <td width="150px" valign="middle"><label for="startdate">End Date:</label></td>
                      <td valign="top"><input type="text" name="enddate" id="enddate" class="required" readonly="readonly"/></td>
                    </tr>';
            break;
        default:
            break;
}
} 

?>
  </table>

  <input type="hidden" id="acyear" name="acyear" value="<?php echo $academic_start_date; ?>"/>
  <input type="hidden" id="user" name="user" value="<?php echo $USER->id; ?>"/>
  <input type="hidden" id="employee" name="employee" value="<?php echo $USER->firstname.' '.$USER->lastname; ?>"/>
 </fieldset>
</form>
</div>

EDIT – What it does

with the following when you click save it does not do anything, the modal stays up and even if you fill the form it does not do anything:

  'Save': function() {
            $("#new_request_form").validate({
             submitHandler: function(form) {
                 submitFormWithAjax($(this).find('form'));
                $(this).dialog('close');
             }
            });

        },

With the following the form gets submitted and works as expected just no validation:

 'Save': function() {
                 submitFormWithAjax($(this).find('form'));
                $(this).dialog('close');

            },
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:34:39+00:00Added an answer on June 11, 2026 at 10:34 am

    I guess when calling submitHandler function, you have passed the wrong selector. $(this) represent the form itself so there is no need to find the form in it.

    So Replace this code

    submitFormWithAjax($(this).find('form'));
    

    With

    submitFormWithAjax($(this));
    

    Or Alternately

    submitFormWithAjax($("#new_request_form"));
    

    This will fix you problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a modal window using jqmodal. I need a button within that modal
I have a form which I load within a modal window in that from
I have a form within an ASP.NET MVC application and I'm trying to submit
I have a basic form with a search input and a submit button within.
I have a dialog form that can be opened as a modal or non-modal
I have a modal dialog form that submits data to a table. I want
I have 2 modal windows that are triggered from button clicks. They work fine
I have a form that submits with Ajax. I want to respond by opening
I have a form and a div within that form that I am using
I have a complex input form within a PHP based web application. To structure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.