| 381 | |
| 382 | |
| 383 | def select_app_without_values(environ, start_response): |
| 384 | req = Request(environ) |
| 385 | status = b"200 OK" |
| 386 | if req.method == "GET": |
| 387 | body = to_bytes(""" |
| 388 | <html> |
| 389 | <head><title>form page</title></head> |
| 390 | <body> |
| 391 | <form method="POST" id="single_select_form"> |
| 392 | <select id="single" name="single"> |
| 393 | <option>Four</option> |
| 394 | <option>Five</option> |
| 395 | <option>Six</option> |
| 396 | <option>Seven</option> |
| 397 | </select> |
| 398 | <input name="button" type="submit" value="single"> |
| 399 | </form> |
| 400 | <form method="POST" id="multiple_select_form"> |
| 401 | <select id="multiple" name="multiple" multiple="multiple"> |
| 402 | <option>Eight</option> |
| 403 | <option selected value="Nine">Nine</option> |
| 404 | <option>Ten</option> |
| 405 | <option selected>Eleven</option> |
| 406 | </select> |
| 407 | <input name="button" type="submit" value="multiple"> |
| 408 | </form> |
| 409 | </body> |
| 410 | </html> |
| 411 | """) |
| 412 | else: |
| 413 | select_type = req.POST.get("button") |
| 414 | if select_type == "single": |
| 415 | selection = req.POST.get("single") |
| 416 | elif select_type == "multiple": |
| 417 | selection = ", ".join(req.POST.getall("multiple")) |
| 418 | body = to_bytes(""" |
| 419 | <html> |
| 420 | <head><title>display page</title></head> |
| 421 | <body> |
| 422 | <p>You submitted the %(select_type)s </p> |
| 423 | <p>You selected %(selection)s</p> |
| 424 | </body> |
| 425 | </html> |
| 426 | """ % dict(selection=selection, select_type=select_type)) |
| 427 | |
| 428 | headers = [ |
| 429 | ('Content-Type', 'text/html; charset=utf-8'), |
| 430 | ('Content-Length', str(len(body)))] |
| 431 | # PEP 3333 requires native strings: |
| 432 | headers = [(str(k), str(v)) for k, v in headers] |
| 433 | start_response(status, headers) |
| 434 | return [body] |
| 435 | |
| 436 | |
| 437 | def select_app_without_default(environ, start_response): |