Proper way to do a Submit Button?

What is the proper way to do a “Submit” button?

I have seen a couple of different ways, and I am not sure which is correct…

<input class="submit" type="submit" value="Process Order" />
<input type="hidden" name="submitted" value="true">

Thanks,

Debbie

Actually, only the first one is a real submit button, the second one is a hidden form field, that is submitted together with the others, without the user knowing it.

Therefore, the first one is the correct one.

I just realized that re-reading some code in a book I had handy! Oops!

So, a follow up question is…

Do I need the second line? Do it add any value?

Debbie

People put hidden fields to carry data between forms that are multi-page/steps.

The author was using it to check if the form was submitted.

Somewhere (??) in one of his books I think he said it was more fail-proof?!

Maybe if the user uses his/her keyboard to hit"enter", I dunno.

Debbie

It was primilarly used with CGI, and such I believe.

I don’t understand how this hidden field could make the form more fail-proof, because even if the user presses Enter the form would behave in the same way as if the user had clicked on the submit button.

Not true.

Different browsers behave different ways.

Debbie

Correct, some version of IE didn’t send the submit button in the POST array if the user hit enter. Using the hidden field was a more reliable method as it would always be sent.

Does that make sense in 2011, though?

Do you know which browsers and version had that issue? IE6 for example?

If it is outdated code I’ll take it out.

Thanks,

Debbie

It does still make sense as IE8 appears to still do it!

Try it: http://refrsh.com/spf/formtest.php

with hitting ENTER


Array ( [testText] => test ) 

Hit submit


Array ( [testText] =>Test [Submit] => Submit ) 

Cool link!! :smiley:

Thanks,

Debbie

Probably because the page has no DTD, thus IE is in quirks mode. Try in standard mode. At least for IE9 it works, if you have standard mode.

EDIT: Yeah, they didn’t fix it in IE8. It appears they did so in IE9. You can clearly see in IE9 (standard mode) how the dotted focus appears on the submit button when hitting ENTER in the field, and the [Submit] => Submit is also sent.

I didn’t know this. You can see that I don’t develop for IE :stuck_out_tongue:

Are you using isset($_POST[‘Submit’]) or if($_POST[‘Submit’]===‘Submit’) to detect a page submission?

I have…


	<input name="submit" type="submit" value="Place Order" />
	<input name="submitted" type="hidden" value="true" />

and then…


	if (isset($_POST['submitted'])){
		// Handle Form.

Sincerely,

Debbie

I didn’t know this, but… I just try it with IE7 and it works like it should be!

The hidden input is not needed.
Both actions are submitting the form, that is what your code should respond to.

Why do you care if they’ve clicked the button or hit enter in a form?

Hello…

Originally Posted by spikeZ View Post
Correct, some version of IE didn’t send the submit button in the POST array if the user hit enter. Using the hidden field was a more reliable method as it would always be sent.

Debbie

What markbrown4 was hinting to, is that you do not really care if the field and value of the submit button anyway.

You can just as easy use “if (!empty($_POST))” to get around this issue.