2014-10-02 109 views
0

在我的網頁我使用兩個提交按鈕在單一表單提交併保存與提交按鈕我想檢查一些驗證onsubmit表單和另一個保存按鈕使用提交數據,因爲它不需要驗證數據是否有任何JavaScript方法來檢查哪些提交被點擊。感謝高級。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 : [email protected]" 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) ?> 
+0

你能爲我們提供這個問題的一個片段提交? – 2014-10-02 04:44:43

+0

什麼阻止用戶總是點擊第二個按鈕,即使需要進行一些驗證? – jeff 2014-10-02 04:45:35

+0

如果它是在單個提交按鈕上完成的。爲什麼你想這樣做? – 2014-10-02 04:47:28

回答

0

你可以使用一個按鈕,而不是當你需要驗證

<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 
    } 
} 
+0

我把所需的所有領域,它也告訴我點擊保存。並且我想提交所需的警報只提交不保存任何解決方案此 – user3300358 2014-10-02 06:25:20

+0

我不確定您可以使用兩個提交和使用所需的屬性是你想要的方式。也許你可以把你想驗證的按鈕作爲提交,並將其他按鈕更改爲這樣的按鈕... '' 這應該只在您使用提交按鈕時調用驗證,而不是保存按鈕 – 2014-10-02 14:00:54