How to test if a form has been submitted?

K

Ken Adams

Basically I have a form submit to the same page and have it output the
results of the submit to the same page. How can I test to see if something
was submitted inorder to get to this page or if this is the first time to
the page. Possible a javascript or JSP method would be fine maybe even the
right way to go.

Thanks a bunch
Ken
 
B

Beauregard T. Shagnasty

Ken said:
Basically I have a form submit to the same page and have it output
the results of the submit to the same page. How can I test to see
if something was submitted inorder to get to this page or if this
is the first time to the page. Possible a javascript or JSP method
would be fine maybe even the right way to go.

You don't say what language you're using, but check the POST variables
at the start of the code.

$bar = $_POST['foo'];
if ($bar) {
// do stuff here
}
 
T

Toby Inkster

Ken said:
Basically I have a form submit to the same page and have it output the
results of the submit to the same page. How can I test to see if something
was submitted

I tend to include this in the form:

<input type="hidden" name="submitted" value="1">

And then test:

<?php
if ($_REQUEST['submitted']==1) {
// form was submitted
} else {
// form not submitted
}
?>

BTS's solution will sometimes break -- for example, if $_POST['foo'] is
the number '0' or the string 'False'. (Though it could be made to work
using the isset() function.)
 
B

Beauregard T. Shagnasty

Toby said:
BTS's solution will sometimes break --

True enough. I should have gone into more details, but since we don't
yet know the language, I was being sparse. <g>

My php forms do much as you describe, though I don't use hidden values.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top