Curious Submit button

I have a .php file that contains an html form that begins with this:

<form method=“POST” action=“<?php echo $PHP_SELF;?>”>

and has a submit button invoked this way:

<input type=“submit” name=“Submit” value=“Submit Form”>

I have discovered that the file does not work without including

name=“Submit”

even though I cannot find another instance of the word Submit in any other statement in the .php file. If I haven’t missed a reference to it, is there some reason why name=“Submit” is required?

Also, name=“submit” doesn’t work either. The string name=“Submit” must be in the submit statement and it must be capitalized. I have seen on the Internet .php files that use only

<input type=“submit” value=“Submit Form”>

for the submit button.

I would appreciate any clarification.

Thank you for your help.

Jim Adrian
<snip/>

Hey jamesadrian,
This sounds like the method I use to submit data back to the server.

How I prefer to do this (for simplicity sake), is to have any forms submit the data back to themselves. Before any page out put is sent to the browser, I have a check looking for $_POST[‘Submit’] (or $_GET[‘Submit’]) being set to the “Value” of the form element. The Value is the text that’s displayed on the button, and in your case “Submit Form”.

If the Variable is set to “Submit Form” that would mean that the form was filled out and the button was clicked. In this case, you’d want to then include the php file that evaluates, parses, checks, stores, processes, emails, or anything else you intended to do with the data.

My own design method for doing this was because I’ve never been a huge fan of using Javascript/Client-side scripting to do form validation. I keep all the validation happening on the server end, and if there is an error, you can then pass the existing, submitted values back to the page and have them be displayed as the default values. You can also set the Class on the labels or form elements themselves to indicate if corrections need to be made.

I can gather up some sample code if my rambling explanation on how I use this is not clear. Let me know.

What do you mean by it “does not work”? As in, the form doesn’t get submitted, or what?

There could be some javascript interfering. Perhaps some “validation” code that accesses the submit button via its name attribute?

Or of course, the other option is that you missed a reference to it. There could be some kind anti-spam check to ensure the submit button was used by a human user, rather than some robot submitting the form. If there are some included files in your PHP file, did you check in there?

I can’t believe it!

The very first statement after <?php is

if (isset($_POST[‘Submit’]))

That’s where the reference is.

In a way, it is a fortunate mistake because your answers have introduced me to additional concepts in php and a more specific understanding of how these statements work.

Thank you all so much for your answers.

Jim Adrian
<snip/>

Somewhere near the top of the page there will be a test to see if $_POST[‘Submit’] exists in order to work out whether the form has been submitted and if so to process it. If the form hasn’t been submitted or if there are errors then it eventually gets to the part of the code where it displays the form.

tbakerisageek,

Sample cod is always of interest. I’m not ready for a reply other that this because I am still confused.

Jim Adrian