By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

HOW TO: Submit a form to PHP with no return?

P: n/a
gsb
HOW TO: Submit a form to PHP with no return?

I need to submit a form for file upload to a PHP script but do not want
anything returned.
That is the TARGET for the form should be like a null device.
I am using a JavaScript function to submit the form.

Is there a way to do this?

gsb
Jul 17 '05 #1
Share this Question
Share on Google+
19 Replies


P: n/a
gsb wrote:
HOW TO: Submit a form to PHP with no return?

I need to submit a form for file upload to a PHP script but do not want
anything returned.
That is the TARGET for the form should be like a null device.
I am using a JavaScript function to submit the form.

Is there a way to do this?

<form method="post" action="null.php">
<!-- ... -->

and

<?php // null.php
// deal with file upload
// *with no* output to the browser

// and then ...
// ...
// ...

exit(0);
?>
What is this for?

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

P: n/a
gsb
Pedro Graca,

Thanks for a quick reply.
However, it does not seem to work.
The target defaults to self and the browser window simply goes blank.

Here is what I get back:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html;
charset=windows-1252"></HEAD>
<BODY></BODY></HTML>

It is for a simple upload page without feedback.
....but I can not make it quiet.

gsb
Jul 17 '05 #3

P: n/a
gsb wrote:
Pedro Graca,

Thanks for a quick reply.
However, it does not seem to work.
The target defaults to self and the browser window simply goes blank.

Here is what I get back:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html;
charset=windows-1252"></HEAD>
<BODY></BODY></HTML>
I see.

Try this:

<?php
// deal with upload
header('Content-Type: text/plain; charset=us-ascii');
echo '';
?>
It is for a simple upload page without feedback.
...but I can not make it quiet.


Why?
Why no feedback?

Not even a simple

Thank you for uploading the file whatever.zip
Now close your browser and go read a book :-)

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #4

P: n/a
gsb
Pedro Graca,

That will send me back a blank page.

Why?
I have a one page site that should not be reloaded due to possible user
rearrangement.
I do not want a popup nor internal iFrame.
So I would like the server to simply not respond or redirect any 'required'
output to a null device or non-existing window.

The file checks and user feed back come from elsewhere.

gsb
Jul 17 '05 #5

P: n/a
gsb wrote:
HOW TO: Submit a form to PHP with no return?

I need to submit a form for file upload to a PHP script but do not want
anything returned.
That is the TARGET for the form should be like a null device.
I am using a JavaScript function to submit the form.

Is there a way to do this?

gsb


gsb, when someone uses a form such as for the purposes of obloading,
that form sends a request to the web server containing the uploaded data.

Because HTTP is a request/response protocol, your browser will "allways"
wait for and act on a response that the server will inevitably
provide (if nothing breaks).

Hence, you always have to put whatever you want to come next in a page
pointed to by the form action attribute.

If you don't want the screen to change, then point the action attribute
to the same file containing the form we are talking about.

A nice trick would be to use the onSubmit javascript event attribute in
the form element to pop up a new window which is also then specified in
the target element of the form attribute. The action attribute in the
form element can then point to a handling script which doesn't output
anything other than
<html><head/><body onload="document.close();" /></html>

Jul 17 '05 #6

P: n/a
gsb wrote:
That will send me back a blank page.
Yes, that is what I thought you wanted.
Why?
I have a one page site that should not be reloaded due to possible user
rearrangement.
I do not want a popup nor internal iFrame.
So I would like the server to simply not respond or redirect any 'required'
output to a null device or non-existing window.


Ah! Maybe your real problem is the "Back/Refresh" one :)

If that is it, I do like something like this:

1. Server sends the form to the browser (GET form.php)
2. User fills the form and submits (POST dealform.php)
3. Server deals with data and redirectes (header('Location: tak.php');)
4. User sees the "Thank you" page (GET tak.php)

If the user now presses Refresh he will be refreshing the GET, not the
POST; and if he presses Back he will be taken to 1. (again the GET and
not the POST)
HTH

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #7

P: n/a
gsb
Well, thank you both.
I now know more than before.

I had hoped for some PHP environment setting that would defeat the "HTTP
request/response protocol" and not send anything back.

So, I will use an internal, dynamically created iFrame and return the very
same page (I only have one page) with an onLoad check like:

<BODY onLoad="if(parent!=self)document.close();">

That will insure that the browser's refresh and back methods will redirect
to itself. Page components are already cached so I expect minimal impact on
performance.

Again, thanks for your time and help.
If you think of anything else, please post: I'll be glad to look.

gsb
Jul 17 '05 #8

P: n/a
"gsb" wrote
I had hoped for some PHP environment setting that would defeat the
"HTTP request/response protocol" and not send anything back.


....so the browser, which does not know about that setting for that specific
website, would show a "request timed out"?

Adriaan.
Jul 17 '05 #9

P: n/a
gsb
In a Javascript newsgroup, Matt Kruse led me to this:

If you haven't used, HTTP Response 204 can be very convenient. 204 tells the
server to immediately termiante this request. This is helpful if you want a
javascript (or similar) client-side function to execute a server-side
function without refreshing or changing the current webpage. Great for
updating database, setting global variables, etc.

header("status: 204"); (or the other call)
header("HTTP/1.0 204 No Response");

Thought that y'all might like to know.

gsb
Jul 17 '05 #10

P: n/a
"gsb" <gs*@QWest.net> wrote in message news:<iJ***************@news.uswest.net>...
Well, thank you both.
I now know more than before.

I had hoped for some PHP environment setting that would defeat the "HTTP
request/response protocol" and not send anything back.

So, I will use an internal, dynamically created iFrame and return the very
same page (I only have one page) with an onLoad check like:

<BODY onLoad="if(parent!=self)document.close();">

That will insure that the browser's refresh and back methods will redirect
to itself. Page components are already cached so I expect minimal impact on
performance.

Again, thanks for your time and help.
If you think of anything else, please post: I'll be glad to look.

When posting please don't change the subject line and try to quote
previous discussions. Your message is totally out of context.

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #11

P: n/a
"gsb" wrote
header("status: 204"); (or the other call)
header("HTTP/1.0 204 No Response");


....but then how you're going to send the file contents to the browser for
download?

Adriaan.
Jul 17 '05 #12

P: n/a
"Adriaan" <re*@de.solidareit> wrote in message news:<40***********************@dreader19.news.xs4 all.nl>...
"gsb" wrote
header("status: 204"); (or the other call)
header("HTTP/1.0 204 No Response");


...but then how you're going to send the file contents to the browser for
download?


OP was talking about "uploading".

FWIW, in a similar discussions Chung Leong was suggested to post the
form to a invisible IFRAME.

--
| Just another PHP saint |
Email: rrjanbiah-at-Y!com
Jul 17 '05 #13

P: n/a
"R. Rajesh Jeba Anbiah" wrote
...but then how you're going to send the file contents to the browser for download?


OP was talking about "uploading".


Ok :-)

Adriaan
Jul 17 '05 #14

P: n/a
gsb
Adriaan,

By that point, the file contents are already on the server and stowed away.

Send me an email if interested and I'll send you a link of the example.
Bare with my proactive "junk-mail" buster.

gsb

gs*@qwest.net
Jul 17 '05 #15

P: n/a
gsb

R. Rajesh Jeba Anbiah,

Returning the results to an invisible iFrame causes the Refresh and back
buttons of the browser (most) to screw up if pressed.
I did not like this option when I tried.

Send me an email if interested and I'll send you a link of the example.
Bare with my proactive "junk-mail" buster.

gsb

gs*@qwest.net

Jul 17 '05 #16

P: n/a
"gsb" <gs*@qwest.net> schrieb im Newsbeitrag
news:5y*****************@news.uswest.net...
HOW TO: Submit a form to PHP with no return?

I need to submit a form for file upload to a PHP script but do not want
anything returned.
That is the TARGET for the form should be like a null device.
I am using a JavaScript function to submit the form.

Is there a way to do this?

gsb


I just thaught of a way somehow like:

- submit the form as usual to $_SERVER['PHP_SELF']
- process form data
- send header("Location: ".$_SERVER['PHP_SELF']."?submitted=yes");
- Include that to the body tag: <?php if(isset($_GET['submitted'])) echo '
onLoad="history.back()"'; ?>

So you get back to where you want.

HTH
Markus
Jul 17 '05 #17

P: n/a
ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) wrote in
news:ab**************************@posting.google.c om:
"gsb" <gs*@QWest.net> wrote in message
news:<iJ***************@news.uswest.net>...

Again, thanks for your time and help.
If you think of anything else, please post: I'll be glad to look.

When posting please don't change the subject line and try to quote
previous discussions. Your message is totally out of context.


You should get a decent newsreader that handles threading properly-- the
problem is yours, not the OPs.

c

Jul 17 '05 #18

P: n/a
Chris Lott wrote:
ng**********@rediffmail.com (R. Rajesh Jeba Anbiah) wrote in
news:ab**************************@posting.google.c om:
When posting please don't change the subject line
That's good advice in general, but needs qualifying: don't change the
Subject line unnecessarily, or to something meaningless. The defender
is charged with both offences, each punishable by unlimited killfile
time.

Knowing whether to change the Subject line is sometimes tricky, but,
if done, it ought to be done sensibly. I've changed this article's
Subject line to reflect its content.
and try to quote previous discussions. Your message is totally out of context.

Indeed.
You should get a decent newsreader that handles threading properly
That's sound advice as well. But the fact remains that
mid:iJ***************@news.uswest.net "is totally out of context".
-- the problem is yours, not the OPs.


We know Google's interface isn't ideal, but would you care to explain
why you attribute the problem to R. Rajesh Jeba Anbiah?

You forgot to read <news:news.newusers.questions>, didn't you? I urge
you to familiarise yourself with the articles routinely posted there,
or their HTML-ised equals, before making yourself look yet more
ignorant [1] of the subject (pun unintended). HTH.

Have a great weekend. :-)
[1] "Ignorant" is often used pejoratively, but isn't here.

--
Jock
Jul 17 '05 #19

P: n/a
"John Dunlop" wrote
(R. Rajesh Jeba Anbiah) wrote
When posting please don't change the subject line


That's good advice in general, but needs qualifying: don't change the
Subject line unnecessarily, or to something meaningless. The defender
is charged with both offences, each punishable by unlimited killfile
time.


....but above all I VERY MUCH welcome everyone to post their final solution
(in the very same thread) rather than only asking for help and not bothering
about posting the result. So, I welcome that specific post by gsb, though it
was missing the context and though the changed subject line was missing the
"(was: ...)" part.

Adriaan
Jul 17 '05 #20

This discussion thread is closed

Replies have been disabled for this discussion.