Connecting Tech Pros Worldwide Forums | Help | Site Map

Python CGI: Hidden fields don't show up in submitted keys!

Newbie
 
Join Date: May 2006
Posts: 1
#1: May 8 '06
Hello all,
The search function of this forum isn't working although I found a similar question on the forum using Google, but the replies don't help me. So, forgive me please if this has been answered before.

I have a cgi program in Python that genereates an HTML page with a form with hidden fields whose values are set via the following:
Expand|Select|Wrap|Line Numbers
  1. ##Print hidden "usernameH", "passwordH", "timeH", "checksumH", and toPageH, fields with value attribs
  2.     print"""
  3.     <input name="usernameH" type="hidden" id="usernameH" value="%s">
  4.     <input name="passwordH" type="hidden" id="passwordH" value="%s">
  5.     <input name="timeH" type="hidden" id="timeH" value="%f">
  6.     <input name="checksumH" type="hidden" id="checksumH" value="%s"></p>
  7.     <input name="toPageH" type="hidden" id="toPageH" value="queryPage"></p>
  8.     <p>
  9.     """%(usernameH, passwordH, timeH, checksumH)
The Submit action is handled with bits of javascript that follow:
Expand|Select|Wrap|Line Numbers
  1. <!--javascript function that returns true if username and password lengths are both greater than zero-->
  2.  
  3. <script language="JavaScript">
  4. function validate() {
  5.     if (loginForm.username.value.length > 0 && loginForm.password.value.length > 0){return true;}
  6.     else{return false;}
  7.     }
  8.     </script>
  9.  
and:
Expand|Select|Wrap|Line Numbers
  1. <FORM name="loginForm" ACTION="hw6mod.cgi" METHOD="POST" onsubmit=" if(!validate()){
  2.     alert('Your username and/or password is blank.'); return false; }">
The problem is that when I Submit the form back to my cgi program and I have the code below, the usernameH and passwordH values are NOT in the keys!
Expand|Select|Wrap|Line Numbers
  1. form = cgi.FieldStorage()
  2. myKeys = form.keys()
  3. def printKeys(myKeys):
  4.     for key in myKeys:
  5.         print """<p>key: %s, value: %s type: %s</p>"""%(key, form[key].value, type(form[key].value))   
  6.  
What's going wrong?

Thanks!

Reply