Edgewall Software

Changes between Initial Version and Version 1 of GenshiRecipes/FormFilling


Ignore:
Timestamp:
Jul 27, 2006, 10:06:52 AM (18 years ago)
Author:
cmlenz
Comment:

Another simple recipe

Legend:

Unmodified
Added
Removed
Modified
  • GenshiRecipes/FormFilling

    v1 v1  
     1= Automatically Populating an HTML Form =
     2
     3The following template provides a match template that automatically adds a `value` attribute to any `<input>` element that has matching data in the context.
     4
     5{{{
     6#!xml
     7<html xmlns:py="http://markup.edgewall.org/">
     8 
     9  <input py:match="form//input" py:attrs="select('@*')"
     10         value="${form[str(select('@name'))]}" />
     11 
     12  <form action="" method="POST">
     13    <p>
     14      <label>Something: <input type="text" name="something"/></label>
     15    </p>
     16  </form>
     17</html>
     18}}}
     19
     20Assuming the context data contained a variable “form” that was `{'something': 'Look, Ma'}`, the output would look as follows:
     21
     22{{{
     23#!xml
     24<html>
     25  <form action="" method="POST">
     26    <p>
     27      <label>Something: <input value="Look, Ma" type="text" name="something" /></label>
     28    </p>
     29    <input value="Send" type="submit" />
     30  </form>
     31</html>
     32}}}
     33
     34This recipe would need to be extended to also support checkboxes, select fields, and so on.
     35
     36----
     37See also: MarkupRecipes, MarkupTemplates