?
Solved

Problem passing "hidden field"

Posted on 2014-10-12
4
Medium Priority
?
144 Views
Last Modified: 2014-10-12
I have a simple html form, with one text field to collect the first name of user (firstname). This page is Form_one.html  and its action page is ActionPage.cgi  

ActionPage.cgi presents  a second form which has a text field asking for persons age. It also has a hidden field which saves the persons (firstname), obtained from Form_one.html.  

ActionPage2.cgi  takes the inputs (firstname and age) and prints out the message :-

Hello FIRSTNAME your age is AGE      (eg Hello James your age is 45)  HOWEVER, what I am getting is ...

Hello None your age is 45.

The value of firstname is apparently not being passed through to ActionPage2  !!!!

Hopefully you can spot the mistake I am making !!     Many thanks in advance,    James

The code for each page Form_one.html  ActionPage.cgi and ActionPage2.cgi  is show below.

_______________________________________________________________________________________________
FORM_ONE.HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="actionpage.cgi" method="get" name="getname" target="_self">
<input name="age" type="text" />
<input name="submitname" type="submit" value="submit" />
</form>
</body>
</html>

____________________________________________________________________________________________
ACTIONPAGE.CGI

#!C:\Python34\python.exe
import cgi, cgitb
def htmlTop():
      print("""Content-type:text/html\n\n
             <!DOCTYPE html>
             <html lang="en">
                 <head>
                  <meta charset="utf-8"/>
                  <title> My Server-side template</title>
             </head>
             <body>""")

def htmlTail():
      print("""</body>
             </html>""")
     
     
     
# Create instance of FieldStorage
form = cgi.FieldStorage()
     
# Get data from fields
firstname = form.getvalue('firstname')



def   createForm(firstname):
      print("""<form method="post" action="actionpage2.cgi">
      Please enter your age: <input type="text" name="age" placeholder="eg... 25">
      <br>
      <input type="hidden" name="firstname" value="{0}" />
      <br>
      <input type="submit" name="submitname" value="submit age"/>
      </form>""".format(firstname))
     
#main program
if __name__== "__main__":
      try:
            htmlTop()
            createForm(firstname)
            htmlTail()
      except:
            cgi.print_exception()

____________________________________________________________________________________________________________
ACTIONPAGE2.CGI
#!C:\Python34\python.exe
import cgi, cgitb
def htmlTop():
      print("""Content-type:text/html\n\n
             <!DOCTYPE html>
             <html lang="en">
                 <head>
                  <meta charset="utf-8"/>
                  <title> My Server-side template</title>
             </head>
             <body>""")

def htmlTail():
      print("""</body>
             </html>""")
     
     
     
# Create instance of FieldStorage
def getData():
      formData = cgi.FieldStorage()
      firstname = formData.getvalue('firstname')
      age = formData.getvalue('age')
      return firstname, age




     
#main program
if __name__== "__main__":
      try:
            htmlTop()
            xyz = getData()
            print("Hello {0[0]} your age is {0[1]}".format( xyz))
            htmlTail()
      except:
            cgi.print_exception()
0
Comment
Question by:jameskane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 40375812
In your initial form page, replace
<input name="age" type="text" />

Open in new window

with
<input name="firstname" type="text" />

Open in new window

0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40375941
Yes, @Robert Schutt, that made it work on my computer.
0
 

Author Closing Comment

by:jameskane
ID: 40376032
Thanks !!

 says me with a red face !!
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40376050
Don't worry about it.  Half my programming time is fixing little things like that.  Especially happens when you copy one file to create another.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question