PDA

View Full Version : php with form submit



prostock3
August 11th, 2007, 07:45 AM
Hi,

I'm uploading a file through php from a form. Everything works, except that after clicking the submit, the browser navigates away from my html page which holds the form. From the form, I go to the url of php file. Is there anyway to stay on the html page after clicking the form submit?

Thanks in advance.

neoguy2012
August 11th, 2007, 07:53 AM
Yes, but it requires a bit of knowledge in AJAX. I would recommend using the onSubmit function in Javascript that'll send it to a function to send your form data through one of those HTTP request thing-a-ma-bobbers.

EDIT:

Here's a link that has some code examples:

http://www.webmasterworld.com/javascript/3136170.htm

prostock3
August 11th, 2007, 04:05 PM
thanks. looks like the guy on the link has the same issue as me. I will try to use ajax to handle the event with some handler.

Do you know why when u click submit, the page gets redirected in the first place?

Thanks!

orlox
August 11th, 2007, 04:12 PM
Actually, if you're submitting files its not possible to use AJAX to do that because of restrictions on the XMLHTTPRequest object that is the core of AJAX. Asynchronous file submitting requires more complex constructs than a simple AJAX request.

However, if you only submit ordinary data, (no files) you can use AJAX to do the submit without changing the current url.

orlox
August 11th, 2007, 04:35 PM
A way in wich you could make the browser return to the page that holds your form would be to direct the action of the form to the same page that holds it, or redirecting from the php script that procceses your form to the php file that contains the form.

Mirrorball
August 11th, 2007, 04:57 PM
I was searching for a way to do this some time ago and the only way is to submit the file to an iframe.