Changes between Version 4 and Version 5 of GenshiRecipes/FormFilling
- Timestamp:
- Sep 24, 2006, 5:22:26 PM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GenshiRecipes/FormFilling
v4 v5 8 8 9 9 <input py:match="form//input[@type='text']" py:attrs="select('@*')" 10 value="${form[str(select('@name'))]}" /> 11 10 value="${form.get(str(select('@name')))}" /> 11 <input py:match="form//input[@type='checkbox']" py:attrs="select('@*')" 12 checked="${form.get(str(select('@name')))}" /> 13 <input py:match="form//input[@type='radio']" py:attrs="select('@*')" 14 py:with="value = form.get(str(select('@name')))" 15 selected="${value and (value == str(select('@value'))) or None}" /> 16 <textarea py:match="form//textarea" py:attrs="select('@*')" 17 py:content="form.get(str(select('@name')))"></textarea> 18 12 19 <form action="" method="POST"> 20 <!--! A simple text field --> 13 21 <p> 14 <label>Something: <input type="text" name=" something"/></label>22 <label>Something: <input type="text" name="name"/></label> 15 23 </p> 24 <!--! A check box --> 25 <p> 26 <label>Enabled: <input type="checkbox" name="enable" /></label> 27 </p> 28 <!--! A text area --> 29 <p> 30 <label for="description">Description</label> 31 <textarea id="description" name="description">Bla bla bla</textarea> 32 </p> 33 <!--! A radio group --> 34 <fieldset> 35 <legend>Select one:</legend> 36 <label py:for="option in ('A', 'B', 'C')"> 37 <input type="radio" name="option" value="$option" /> 38 </label> 39 </fieldset> 16 40 </form> 17 41 </html> 18 42 }}} 19 43 20 Assuming the context data contained a variable “form” that was `{'something': 'Look, Ma'}`, the output would look as follows: 44 Assuming the context data contained a variable “form” that was set to: 45 46 {{{ 47 #!python 48 form = {'name': 'Look, Ma', 49 'enable': '', 50 'option': 'B', 51 'description': 'This is the description someone put in here'} 52 }}} 53 54 Then the output would look as follows: 21 55 22 56 {{{ … … 25 59 <form action="" method="POST"> 26 60 <p> 27 <label>Something: <input value="Look, Ma" type="text" name=" something" /></label>61 <label>Something: <input value="Look, Ma" type="text" name="name" /></label> 28 62 </p> 29 <input value="Send" type="submit" /> 63 <p> 64 <label>Enabled: <input type="checkbox" name="enable" /></label> 65 </p> 66 <p> 67 <label for="description">Description</label> 68 <textarea id="description" name="description">This is the description someone put in here</textarea> 69 </p> 70 <fieldset> 71 <legend>Select one:</legend> 72 <label> 73 <input type="radio" name="option" value="A" /> 74 </label> 75 <label> 76 <input selected="selected" type="radio" name="option" value="B" /> 77 </label> 78 <label> 79 <input type="radio" name="option" value="C" /> 80 </label> 81 </fieldset> 30 82 </form> 31 83 </html> 32 84 }}} 33 85 34 This recipe would need to be extended to also support checkboxes, select fields, and so on.86 This recipe would need to be extended to also support select fields. 35 87 36 88 ----