0

I have a form that has several checkboxes and text boxes whose values are all passed by one submit button to a different url. However, I am now trying to write the new url page but dont know how to access those values.

<form name="myform" action="result" method = "get">

        <fieldset>
            <input type="checkbox" value="total_money" name="check" onchange="javascript:toggle('money');" /> Filter by Total Money</br>

                <div id="money" style="display:none" name="option">  

                    <input type="checkbox" value="more" onchange="javascript:toggleLine('money_text');"  name="condition"/> <label for="condition" > > </label>

                        <div id = "money_text" style="display:none"  >
                            <input type="text" id="money_box" name="money_name" value="lower limit" />
                        </div></br>

                    <input type="checkbox" value="less" onClick="javascript:toggleLine('money_text1');" name="condition"/> <label for="condition1"> < </label>

                        <div id = "money_text1" style="display:none;"  >
                            <input type="text" id="money_box1" name="money_name1" value="upper limit" />
                        </div>

                </div>

            <input type="checkbox" value="employees" name="check" onchange="javascript:toggle( 'employees');"/> Filter by Employees</br>

                <div id="employees" style="display:none" name="option"> 

                    <input type="checkbox" value="more" onchange="javascript:toggleLine('employees_text');" name="condition"/> <label for="condition" > > </label>

                        <div id = "employees_text" style="display:none"  >
                            <input type="text" id="employees_box" name="employees_name" value="lower limit" />
                        </div></br>

                    <input type="checkbox" value="less" onClick="javascript:toggleLine('employees_text1');" name="condition"/> <label for="condition1"> < </label>

                        <div id = "employees_text1" style="display:none;"  > 
                            <input type="text" id="employees_box1" name="employees_name1" value="upper limit" />
                        </div>
                </div>                         
        </fieldset>
    <input type="submit" value="Submit" />
</form>​

the url response that I get looks something like this (dependent on whats checked or not/input):

url:   http://127.0.0.1:8000/crunchApp/result?check=total_money&condition=more&money_name=lower+limit&money_name1=upper+limit&check=employees&employees_name=lower+limit&condition=less&employees_name1=upper+limit

I need to use this criteria as parameters for python methods that search a database but cant seem to figure out how. Any help would be greatly appreciated!

Santiago
  • 1,984
  • 4
  • 19
  • 24

2 Answers2

0

This could have been found with a little searching.

http://www.daniweb.com/software-development/python/threads/22312/get-posted-form-data-in-python

python cgi script--->addDo.cgi

import cgitb; cgitb.enable()
import cgi
import sys
form = cgi.FieldStorage()

// THIS IS WHERE THE VARIABLE IS READ FROM THE HTTP FORM POST
photos = form["photolist"]

i=0
for photo in photos:
    i = i + 1
    finalPhoto = finalPhoto + "," + photo[i]
FlavorScape
  • 13,301
  • 12
  • 75
  • 117
  • sorry but I dont know what this means. This is a python script but I am trying to write the html page that reads the values given by another html page. Where would this code go/what does it do? – Santiago Aug 24 '12 at 00:24
  • You're submitting a form right? so you need to get POST variables. You can't do anything with just HTML on the receiving end of a post. You said you needed to get the variables into Python to query a database. Well, that's what this does. – FlavorScape Aug 24 '12 at 19:16
0

you could do this in bottle easily if you wanted to using something similar to this:

from bottle import route,request,static_file,template

@route('/mypage',method="GET")
def get_mypage():
    #return static_file('mypagetopost.html')  #you can use either static_file or template
    return template('mypagetopost.tpl')
@route('/mypage',method="POST")
def post_mypage():
    money_text=request.forms.get("money_text")  #you get the value of the form by getting it by name.
    #return "Your money_text text was:%s" % money_text
    return template('yourposttemplate.tpl',yourpostpagevarformoney_text=money_text) #you can pass variables to your template through returning the template, however you cannot do this with static_file

tweaking in your html page required: add: action="/mypage" method="post" to your submit.

Also note that in using the WSGI server with bottle by default, you need to setup static file handlers (for css/js/static html) and change your linking accordingly.

IT Ninja
  • 6,174
  • 10
  • 42
  • 65