Twitter Bootstrap 2 modal form dialogs

后端 未结 5 1920
失恋的感觉
失恋的感觉 2021-01-30 12:01

I have the following dialog form :


      
      
5条回答
  •  北恋
    北恋 (楼主)
    2021-01-30 12:29

    Your submit button is outside of the form tags.
    It won't know what form to submit.

    Use javascript to connect it to the form.

    
    
    
    
    
    

    As for the × that is supposed to link to the homepage, why not just remove the data-dismiss='modal' and make it act like a normal link using a standard href='home.html'.

    Here is some additional code to point you in the right direction for using AJAX to submit the form:

    // Since we want both pressing 'Enter' and clicking the button to work
    // We'll subscribe to the submit event, which is triggered by both
    
    $('#modal-form').on('submit', function(){
    
      //Serialize the form and post it to the server
      $.post("/yourReceivingPage", $(this).serialize(), function(){
    
        // When this executes, we know the form was submitted
    
        // To give some time for the animation, 
        // let's add a delay of 200 ms before the redirect
        var delay = 200;
        setTimeout(function(){
          window.location.href = 'successUrl.html';
        }, delay);
    
        // Hide the modal
        $("#my-modal").modal('hide');
    
      });
    
      // Stop the normal form submission
      return false;
    });
    

提交回复
热议问题