When does the html input type submit get set?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi everyone,

I've got a rather unconventional architecture that I'm having problems

I have a form called "searchForm", that has an input of type "submit"
(with name = "submitButton for argument sake). What happens when the
form is submitted (when the submit button is clicked...) depends on
some previous user input. In one case, the onsubmit handler calls a
function that does basic input checking, and returns true if all the
inputs are correct, and thus submits the form:

onsubmit = "return submitSearchForm"

In the other case, the onsubmit handler calls some java functions that
accomplish some other functionality, and the java functions themselves
call submit on the form:

onsubmit = "doStuff(); return false;"

function doStuff()
//..do some other complicate stuff

In the latter case, the form seems to get submitted, because the page
reloads. Also, the $_POST variables that the form submits are set.
However, in the latter case, the $_POST['submitButton'] variable is not
set, even though the form was submitted by clicking on the submit
button! In the prior case, the $_POST['submitButton'] is set.Why is
this the case? Does it have something to do with the fact that the form
was submitted by a function, rather than the onsubmit handler?

Are there any elegant workarounds to this problem (I use the
$_POST['submitButton'] value to check if the form has been submitted -
if it has, I do some processing on the form's inputs)?. One way I can
think of is having a hidden input called 'formSubmitted' which is
initially set to false, and prior to calling submit() on the form, you
set this input to true, and you can test to see if this value is true
in addition to testing if $_POST['submitButton'] is set:

if ( isset($_POST['submitButton']) || formSubmitted == 'true')
 //.. do some form processing

Any help would be appreciated!



Re: When does the html input type submit get set?


Quoted text here. Click to load it


Quoted text here. Click to load it

Your inkling was right.  The form wasn't submitted using the submit
button but by the javascript function submit(), because onsubmit
returned false, and so the name-value pair of the submit button was not
sent as part of the form data, the submit button not being a
'successful control'.

Quoted text here. Click to load it

Only concern is that it relies on javascript to toggle the hidden
value, but then maybe that's neither here nor there since you appear
to be relying heavily on javascript already.  I would think a hidden
input of some sort is the way to go.


Re: When does the html input type submit get set?

Thanks, its good to get guesses confirmed by someone that knows what
they're talking about :)

Yeah, the site heavily relies on javascript, and I don't see why this
would be a problem with today's modern browsers (I imagine most of the
population would use either FF, IE, NN, or Safari). The only exception
I can think of is browsing via WAP.



Re: When does the html input type submit get set?

Taras_96 wrote:
Quoted text here. Click to load it

It's a problem because more and more people turn off javascript, largely  
  because of all the holes in browsers (not to mention any names).

IMHO, javascript is great for improving the functionality of a site -  
but no site should rely on javascript for it's basic functionality.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline