javascript方法来检查带有两个或多个提交按钮的表单提交


javascript method to check form submition with two or more submit button

在我的网页中,我在单个表单中使用两个两个提交按钮提交和保存。使用提交按钮,我想在提交表单时检查一些验证,另一个保存按钮用于提交数据,因为不需要验证数据。有没有任何javascript方法可以检查单击了哪个提交。提前感谢。

   <?php include(ADMIN_HEADER) ?>
        <script src="//code.jquery.com/jquery-1.10.2.js"></script>
        <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
    <body>
    <section class="account-container register">
    <section class="content clearfix">
        <form action="" method="post" onSubmit="return validateForm();" name="registration" enctype="multipart/form-data">

            <h3>STUDENT ENROLLMENT FORM</h3><br>
            <section class="login-fields">
            <?php
                if(isset($message))
                {
                    ?>
                    <script>
                        alert ("<?php echo $message;?>");
                    </script>
                    <?php
                }
            ?>  
                <section class="emp">
                    <p><b>PERONAL DETAILS</b></p>
                    <section class="field">
                        <label>Full Name</label>
                        <input type="text" name="first_name" placeholder="First Name" required class="login1" title="First Name: Only Character" autocomplete="off" >
                        <input name="last_name" placeholder="Last Name" required class="login1_1" title="Last Name: Only Character" autocomplete="off" type="text">
                    </section> <!-- /field -->
                    <section class="field">
                        <label for="father_name">Father's Name</label>
                        <input name="father_name" placeholder="Father's Name" class="login" title="Father's Name: Only Character" autocomplete="off" type="text">
                    </section> <!-- /field -->
                    <section class="field">
                        <label for="dob">Date Of Birth</label>
                        <input type="text" id="datepicker_1" class="login1" placeholder="Date of Birth" required name='dob'>
                        <label for="blood_group">Blood Group</label>
                        <select name="blood_group" class="login1_1" style="margin-left:4%;width:130px" title="Blood Group">
                            <option selected="selected" value="">Blood Group</option>
                            <option value="O+">O+</option>
                            <option value="O-">O-</option>
                            <option value="A+">A+</option>
                            <option value="A-">A-</option>
                            <option value="B+">B+</option>
                            <option value="B-">B-</option>
                            <option value="AB+">AB+</option>
                            <option value="AB-">AB-</option>
                       </select>
                    </section> <!-- /field -->
                    <section class="field">
                        <label for="email">Email</label>
         <input name="email" placeholder="Email" required class="login" title="Email : abc@gmail.com" autocomplete="off" type="email">
                    </section> <!-- /field -->
                    <section class="field">
                        <label for="password">Password</label>
         <input name="password" placeholder="Password" required class="login" title=" Password" autocomplete="off" type="text">
                    </section> <!-- /field -->
                    <section class="field">
                        <label for="mobile">Mobile No</label>
                        <input name="mobile" placeholder="Mobile No" required class="login1" title="Mobile No.:Only Number" maxlength="12" min="10" autocomplete="off" type="text">
                        <label for="alt_mobile">Alternate Mobile No.</label>
                        <input name="alt_mobile" placeholder="Alternate Mobile No." class="login1_1" title="Alternate Mobile No.:Only Number" maxlength="12" min="10" autocomplete="off" type="text">
                    </section> <!-- /field -->
                    <section class="field">
                        <label for="qualification">Qualification</label>
                        <input name="qualification" placeholder="Qualification" required class="login" title="Qualification" autocomplete="off" type="text">
                    </section> <!-- /field -->
                    <section class="field">
                        <label for="address1">Address 1</label>
                        <textarea name="address1" placeholder="Address 1" required class="login" cols="63" rows="5" title=""></textarea>
                    </section> <!-- /field -->
                    <section class="field">
                        <label for="address2">Address2</label>
                        <textarea name="address2" placeholder="Address 2" class="login" cols="50" rows="5" title=""></textarea>
                    </section> <!-- /field -->
                    <section class="field">
                       <span class="txtphoto"> Photograph</span>
                        <input required name="photo" id="photoId" class="loginphoto" title="Photo:Only Image" type="file">
                    </section> <!-- /field -->
                </section>
                <section class="emp_2">
                    <p><b>EDUCATION DETAILS</b></p>
                     <section class="field">
                        <label for="user_id">DEGREE</label>
        <input placeholder="Degree" name="degree" required class="login" title="Degree" autocomplete="off" type="text">
                    </section> <!-- /field -->
                    <section class="field">
                        <label for="company">COLLEGE  </label>
                        <input name="college" placeholder="College Name" required class="login" title="College Name" autocomplete="off" type="text">
                    </section> <!-- /field -->
                    <section class="field">
                        <label for="company">RESULT %</label>
                        <input name="result" placeholder="Result %" required class="login" title="Result %" autocomplete="off" type="text">
                    </section> <!-- /field -->
                     <section class="field">
                        <a href="">Add More</a>
                     </section>
                    <p>
                        <b>ENROLLMENT DETAILS</b>
                    </p>
                    <section class="field">
                        <label for="user_id">Course</label>
        <input placeholder="Course" name="course" required class="login1" title="Course" autocomplete="off" type="text">
                      <input name="course_code" placeholder="Course Code" class="login1_1" title="Course code" maxlength="12" min="10" autocomplete="off" type="text">  
                    </section> <!-- /field -->
                    <section class="field">
                        <label for="doj">Starting Date</label>
                       <input name="starting_date" id='datepicker_2' placeholder="Starting Date" required class="login1" title="DOS : dd-mm-yyyy" autocomplete="off" type="text">
                       <input name="complition_date" id="datepicker_3" placeholder="Complition Date" required class="login1_1" title="Complition date" autocomplete="off" type="text">
                       </section>                       
                       <section class="field">
                        <label for="doj">Batch Time</label>
                        <input name="batch_start_time" placeholder="Batch Start Time" required class="login1" title="Batch Time" autocomplete="off" type="text">                 <input name="batch_end_time" placeholder="Batch End Time" required class="login1_1" title="Batch Time" autocomplete="off" type="text">
                        </section>
                       <section class="field">
<label for="Practice_hours">Practice Hours</label>
                        <select name="practice_hours" class="login1_1" style="width:150px;" title="Practice Hours">
                            <option selected="selected" value="">Practice Hours</option>
                            <option value="1">1 Hour</option>
                            <option value="2">2 Hour</option>
                            <option value="3">3 Hour</option>
                            <option value="4">4 Hour</option>
                            <option value="5">5 Hour</option>
                       </select>                       
                    <p>
                        <b>PAYMENT DETAIL</b>
                    </p>    
                    <!--<div class="field"><b>Bank Account Detail</b></div> <!-- /field -->
                    <section class="field">
                        <label for="bank">Total Amount</label>
                        <input name="total_amount" placeholder="Total Amount" required class="login1" title="Amount"  type="text">
                        <label for="branch">INSTALLMENT</label>
                        <input name="total_installment" placeholder="Total Installment" required class="login1_1" title="Installment" autocomplete="off" type="text">
                    </section> <!-- /field -->
                    <section class="field">
                        <label for="Installment paid date">Installment Paid Date</label>
                        <input name="inst_paid_date" id="datepicker_4" placeholder="Installment Paid Date" required class="login1" title="Installment Paid date" autocomplete="off" type="text">
                         <label for="Next Installment Date">Next Installment Date</label>
                        <input type="text" name="next_inst_date" id="datepicker_5" placeholder="Next Installment Date" required class="login1_1" value="" title="Installment : dd-mm-yyyy" autocomplete="off">
                    </section> <!-- /field -->
                    <section class="field">
                        <label for="receipt_no">Receipt No</label>
                        <input name="receipt_no" placeholder="Receipt No" required class="login1" title="Receipt No" autocomplete="off" type="text">
                         <label for="Paid Installment">Paid Installment</label>
                        <input type="text" name="paid_installment" placeholder="Paid Installment" required class="login1_1" value="" title="Paid Installment" autocomplete="off">
                    </section> 
                    <section class="field">
                        <label for="counsellor">Counsellor</label>
                        <input name="counsellor" placeholder="Counsellor" required class="login1" title="Counsellor" autocomplete="off" type="text">

                    </section> 
                </section> 
            </section> <!-- /login-fields -->
            <section class="login-actions">
                <button type="submit" class="button btn btn-primary btn-large" name="submit">Register</button>
                <button type="reset" class="button btn btn-primary btn-large">Reset</button>
                <button type="submit" class="button btn btn-primary btn-large" name="save">Save</button>
            </section> <!-- .actions -->
        </form>
    </section> <!-- /content -->
</section> <!-- /account-container -->

        <!-- /footer -->
        <!-- Le javascript
    ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->

<script src="Registration_files/jquery-ui.js"></script><script src="Registration_files/registration.js"></script></body></html>
   <?php include(ADMIN_FOOTER) ?> 

当您需要验证时,您可以使用按钮而不是提交

<input type="button" name="submit" value="Register" onclick="validateAndSubmit();" />
function validateAndSubmit()
{
    //validate form here
    if(valid)
    {
       document.getElementsByTagName("form")[0].submit();
    }
    else
    {
       //tell them what to fix
    }
}