Mike Orr avatar Mike Orr committed cb495bd

Preserve case of "method" arg in ``button_to()`` for XHTML compatibility.

Comments (0)

Files changed (3)

     helper, including the magic ``_method`` field. The IDs will clash if there
     are multiple forms on the page.
 
+* webhelpers.html.tools:
+
+  - Preserve case of "method" arg in ``button_to()`` for XHTML compatibility. 
+
 1.1 (2010-08-09)
 ----------------
 

tests/test_tools.py

     def test_button_to_with_method_delete(self):
         self.assertEqual(u"<form action=\"http://www.example.com\" class=\"button-to\" method=\"POST\"><div><input id=\"_method\" name=\"_method\" type=\"hidden\" value=\"DELETE\" /><input type=\"submit\" value=\"Hello\" /></div></form>", 
             button_to("Hello", "http://www.example.com", method='DELETE'))
-        self.assertEqual(u"<form action=\"http://www.example.com\" class=\"button-to\" method=\"POST\"><div><input id=\"_method\" name=\"_method\" type=\"hidden\" value=\"delete\" /><input type=\"submit\" value=\"Hello\" /></div></form>", 
+        self.assertEqual(u"<form action=\"http://www.example.com\" class=\"button-to\" method=\"post\"><div><input id=\"_method\" name=\"_method\" type=\"hidden\" value=\"delete\" /><input type=\"submit\" value=\"Hello\" /></div></form>", 
             button_to("Hello", "http://www.example.com", method='delete'))
 
     def test_button_to_with_method_get(self):

webhelpers/html/tools.py

     
         # inside of controller for "feeds"
         >> button_to("Edit", url(action='edit', id=3))
-        <form method="POST" action="/feeds/edit/3" class="button-to">
+        <form method="post" action="/feeds/edit/3" class="button-to">
         <div><input value="Edit" type="submit" /></div>
         </form>
     
         not in the middle of a run of text, nor can you place a form
         within another form.
         (Bottom line: Always validate your HTML before going public.)
+
+    Changed in WebHelpers 1.2: Preserve case of "method" arg for XHTML
+    compatibility. E.g., "POST" or "PUT" causes *method="POST"*; "post" or
+    "put" causes *method="post"*.
     
     """
     if html_attrs:
     if method.upper() in ['PUT', 'DELETE']:
         method_tag = HTML.input(
             type='hidden', id='_method', name_='_method', value=method)
-    
-    form_method = (method.upper() == 'GET' and method) or 'POST'
+  
+    if method.upper() in ('GET', 'POST'):
+        form_method = method
+    elif method in ('put', 'delete'):
+        # preserve lowercasing of verb
+        form_method = 'post'
+    else:
+        form_method = 'POST'
     
     url, name = url, name or url
     
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.