Skip to content

Commit

Permalink
Merge pull request #139 from matt-hickford/forms
Browse files Browse the repository at this point in the history
Add endpoint /forms/post with simple HTML form that submits to /post
  • Loading branch information
kennethreitz committed May 30, 2014
2 parents 8da97c4 + 045f0f8 commit beae3f4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions httpbin/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ def view_cookies(hide_env=True):
return jsonify(cookies=cookies)


@app.route('/forms/post')
def view_forms_post():
"""Simple HTML form."""

return render_template('forms-post.html')


@app.route('/cookies/set/<name>/<value>')
def set_cookie(name, value):
"""Sets a cookie and redirects to cookie list."""
Expand Down
29 changes: 29 additions & 0 deletions httpbin/templates/forms-post.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<!-- Example form from HTML5 spec http://www.w3.org/TR/html5/forms.html#writing-a-form's-user-interface -->
<form method="post" action="/post">
<p><label>Customer name: <input name="custname"></label></p>
<p><label>Telephone: <input type=tel name="custtel"></label></p>
<p><label>E-mail address: <input type=email name="custemail"></label></p>
<fieldset>
<legend> Pizza Size </legend>
<p><label> <input type=radio name=size value="small"> Small </label></p>
<p><label> <input type=radio name=size value="medium"> Medium </label></p>
<p><label> <input type=radio name=size value="large"> Large </label></p>
</fieldset>
<fieldset>
<legend> Pizza Toppings </legend>
<p><label> <input type=checkbox name="topping" value="bacon"> Bacon </label></p>
<p><label> <input type=checkbox name="topping" value="cheese"> Extra Cheese </label></p>
<p><label> <input type=checkbox name="topping" value="onion"> Onion </label></p>
<p><label> <input type=checkbox name="topping" value="mushroom"> Mushroom </label></p>
</fieldset>
<p><label>Preferred delivery time: <input type=time min="11:00" max="21:00" step="900" name="delivery"></label></p>
<p><label>Delivery instructions: <textarea name="comments"></textarea></label></p>
<p><button>Submit order</button></p>
</form>
</body>
</html>
1 change: 1 addition & 0 deletions httpbin/templates/httpbin.1.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ <h2 id="ENDPOINTS">ENDPOINTS</h2>
<li><a href="/robots.txt" data-bare-link="true"><code>/robots.txt</code></a> Returns some robots.txt rules.</li>
<li><a href="/deny" data-bare-link="true"><code>/deny</code></a> Denied by robots.txt file.</li>
<li><a href="/cache" data-bare-link="true"><code>/cache</code></a> 200 unless If-Modified-Since was sent, then 304.</li>
<li><a href="/forms/post" data-bare-link="true"><code>/forms/post</code></a> HTML form that submits to <code>/post</code>.</li>
</ul>


Expand Down

0 comments on commit beae3f4

Please sign in to comment.