开发者

Is it possible to submit a form and not load the new window?

开发者 https://www.devze.com 2023-03-28 07:12 出处:网络
I currently have a form set up that passes some data to a php file which does some processing in the background that is not important for the user to see. Currently, when the submit button is clicked,

I currently have a form set up that passes some data to a php file which does some processing in the background that is not important for the user to see. Currently, when the submit button is clicked, a new window is opened (loading 开发者_运维问答the php file that handles the inputted information). As there is no real user content, the page is just blank. Ideally, I would just like the current page to be modified when the form is submitted (have the form disappear and have a message appear in its place, something like "Your request has been received.").

Would it be possible to submit the form and have the data processed without having to open the new window? Is it possible to hide this from the user somehow?

<form action="<!-- FORM ACTION -->" method="post" target="_blank">


With jquery you could do something like:

$('form').submit(function(){
  $.ajax({  
    type: "POST",  
    url: "post.php",  
    data: $('form').serialize(),  
    success: function() {  
      //something to let the user know it was submitted  
    }  
  });
}


Look into ajax. Particularly using a library like jQuery.

http://api.jquery.com/jQuery.ajax/


It is indeed possible. The technique used to accomplish this is called "AJAX" which stands for "Asynchronous JavaScript and XML."

Here is a link to get you started: Submit A Form Without Page Refresh

I would also recommend looking into the JavaScript library, jQuery as it will make your life a lot simpler. jQuery even has a plugin to do exactly what you want to do: jQuery Form Plugin


You could use a header to redirect the action page back to the form page like using a login form, sending it out to get processed then returning back to the page with the session id set.

header ('Location:redirect_page.php');

or use jQuery with ajax like Samusaaron3 said.

0

精彩评论

暂无评论...
验证码 换一张
取 消