Connecting Tech Pros Worldwide Help | Site Map

When does the html input type submit get set?

 
LinkBack Thread Tools Search this Thread
  #1  
Old January 29th, 2006, 07:45 AM
Taras_96
Guest
 
Posts: n/a
Default When does the html input type submit get set?

Hi everyone,

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

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
document.getElementById('searchForm').submit()
}

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!

Cheers

Taras


  #2  
Old January 29th, 2006, 09:35 AM
John Dunlop
Guest
 
Posts: n/a
Default Re: When does the html input type submit get set?

Taras_96:
[color=blue]
> document.getElementById('searchForm').submit()[/color]

[...]
[color=blue]
> However, in the latter case, the $_POST['submitButton'] variable is not
> set, even though the form was submitted by clicking on the submit
> button![/color]

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'.
[color=blue]
> One [workaround] 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:[/color]

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.

--
Seoc

  #3  
Old January 30th, 2006, 04:35 AM
Taras_96
Guest
 
Posts: n/a
Default 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.

Cheers

Taras

  #4  
Old January 30th, 2006, 09:45 AM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: When does the html input type submit get set?

Taras_96 wrote:[color=blue]
> 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.
>
> Cheers
>
> Taras
>[/color]

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.
jstucklex@attglobal.net
==================
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.