The Artima Developer Community
Sponsored Link

Web Buzz Forum
Beware of form parameters named 'submit'

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Cheah Chu Yeow

Posts: 883
Nickname: redemption
Registered: Jun, 2003

Cheah Chu Yeow is no one of any importance
Beware of form parameters named 'submit' Posted: Aug 15, 2006 12:12 PM
Reply to this message Reply

This post originated from an RSS feed registered with Web Buzz by Cheah Chu Yeow.
Original Post: Beware of form parameters named 'submit'
Feed Title: redemption in a blog
Feed URL: http://blog.codefront.net/xml/rss20/feed.xml
Feed Description: ramblings of a misfit - web development, Mozilla, Firefox, Thunderbird, CSS, programming
Latest Web Buzz Posts
Latest Web Buzz Posts by Cheah Chu Yeow
Latest Posts From redemption in a blog

Advertisement

Well, that is if you are ever going to be submitting the form via Javascript. We had to generate forms on the fly and POST them behind the scenes (i.e. in hidden <iframe>s), and got a decent script going, until a particular case failed for no apparent reason. I finally found that the problem was due to a form parameter named “submit” that overwrote the submit() function of the <form>. That’s, of course, after looking at all the wrong places.

So this doesn’t work:

<form id="ninjaForm" action="/come/get/some" method="post">
  <input id="someParam" name="someParam"
    type="hidden" value="Some value" />
  <input id="submit" name="submit"
    type="hidden" value="Start search" />
</form>
<script type="text/javascript">
  setTimeout("document.ninjaForm.submit()", 200);
</script>

When the browser tries to execute “document.ninjaForm.submit()”, it sees the “submit” form field (which overwrote the submit() function) instead and complains that “submit is not a function”.

Do this instead:

<form id="ninjaForm" action="/come/get/some" method="post">
  <script type="text/javascript">
    // Alias the submit function in case there is a 'submit' param.
    ninjaForm = document.getElementById('ninjaForm');
    ninjaForm.__submit = ninjaForm.submit;
  </script>
  <input id="someParam" name="someParam"
    type="hidden" value="Some value" />
  <input id="submit" name="submit"
    type="hidden" value="Start search" />
</form>
<script type="text/javascript">
  setTimeout("ninjaForm.__submit();", 200);
</script>

That’s one way to workaround, of course, and we can get away with the “ninjaForm” global in this case.

Read: Beware of form parameters named 'submit'

Topic: The Cost of Making a Decision Previous Topic   Next Topic Topic: Transitioning From Object-Oriented to Resource-Oriented Programming

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use