2

I am trying to create a simple checkbox that sends the data to server here is my html code.

<form action="." method="POST">
<div class="checksheet">

    <input id="XML Parser" class="checkbox" type="checkbox"/>XML Parser
    <input id="Feed Parser" class="checkbox" type="checkbox"/>Feed Parser
    <input id="Text Parser" class="checkbox" type="checkbox"/>Text Parser
    <input id="Case Normalization" class="checkbox" type="checkbox"/>Case Normalization
    <input id="Stemmer" class="checkbox" type="checkbox"/>  Stemmer

</div>

<div class="submit"><input type="submit"  value="Send" name="raw_text"></div>
</form>

What I am trying to do is very similar to the question asked here: Send Data from a textbox into Flask? But except with the text box.. I have checkboxes.

But I get this error:

Not Found

The requested URL was not found on the server.

If you entered the URL manually please check your spelling and try again.

MY server side code (in flask) is:

@app.route('/raw_text.html')
def home ():
    file = "sample.xml"
    contents = open(file).read()

    contents = contents.decode('utf-8')
    return render_template('raw_text.html',  contents=contents,file=file)

@app.route('/raw_text.html',methods=['POST'])
def get_data():
    print "REQUEST ",request.form()
    data = request.form['raw_text']
    print data
    return "Processed"

Any suggestions. Thanks

Community
  • 1
  • 1
frazman
  • 32,081
  • 75
  • 184
  • 269

1 Answers1

2

A few things:

  1. Your checkbox elements need a name attribute, this is what is used when the data is sent to the back end. Each checkbox that is related to each other needs to have the same name.

  2. Your action attribute needs to point to a URL. If you are posting it to the same page as the form, you can remove the attribute.

  3. ID's cannot contain spaces.

  4. To be accessible the check boxes need <label>s,

Ryan B
  • 3,364
  • 21
  • 35
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284