Commits

Anonymous committed 9822b18

Creating first version of Dragonfly forms plugin

Comments (0)

Files changed (3)

example-site/dragonfly-framework/plugins-inactive/dragonfly_forms.lsp

-;;  Copyright (C) <2009> <Marc Hildmann>
-;;
-;;  This program is free software: you can redistribute it and/or modify
-;;  it under the terms of the GNU General Public License as published by
-;;  the Free Software Foundation, either version 3 of the License, or
-;;  (at your option) any later version.
-;;
-;;  This program is distributed in the hope that it will be useful,
-;;  but WITHOUT ANY WARRANTY; without even the implied warranty of
-;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-;;  GNU General Public License for more details.
-;;  You should have received a copy of the GNU General Public License
-;;  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-;;
-;; @module Dragonfly
-;; @author Marc Hildmann <marc.hildmann at gmail.com>
-;; @version 0.20
-;; 
-;; @location http://code.google.com/p/dragonfly-newlisp/
-;; @description A newLISP web framework for rapid web development
-;; <h4>About Dragonfly web framework</h4>
-;; <p>Dragonfly is a small web framework which is currently under heavy development.
-;; Its's features are a short learning curve, lightweight and fun in programming - 
-;; just like newLISP itself.</p>
-
-;===============================================================================
-; !Loading modules and defining new context
-;===============================================================================
-
-(context 'Dragonfly)
-
-;===============================================================================
-; !Form Functions
-;===============================================================================
-
-;; @syntax (Dragonfly:form_open <form_action> <form_method)
-;; @param <name> a string containing the form action
-;; @param <name> a string containing the form submit method POST/GET
-;; <p>Writes a standard form open element</p>
-;; 
-(define (form-open form_action form_method)
-  (print "<table><form action='"form_action"' method='"form_method"'>")
-)
-
-;; @syntax (Dragonfly:form_textfield <form_name>)
-;; @param <name> a string containing the text field name
-;; <p>Writes a standard form field with size '30'</p>
-;; 
-(define (form-textfield form_name)
-  (print "<tr class='form_row'><td class='form_label'><label for='"form_name"'>"(title-case form_name)"</label></td><td class='form_input'><input id='"form_name"' name='"form_name"' size='30' type='text' /></td></tr>")
-)
-
-;; @syntax (Dragonfly:form_submit <form_value>)
-;; @param <value> a string containing the value for the submit button
-;; <p>Writes a standard form submit button.</p>
-;; 
-(define (form-submit form_value)
-  (print "<tr class='form_row'><td class='form_label'>&nbsp;</td><td class='form_input'><input id='commit' type='submit' value='"form_value"' /></td></tr>")
-)
-
-;; @syntax (Dragonfly:form-submit-js <form_action> <form_value>)
-;; @param <form_action> a string containing the URI after submitting the submit button
-;; @param <form_value> a string containing the value for the submit button
-;; <p>Writes a form submit button with some javascript
-;; which modifies the action attribute.</p>
-;; 
-(define (form-submit-js form_action form_value)
-  (print "<tr class='form_row'><td class='form_label'>&nbsp;</td><td class='form_input'><input id='commit' type='button' value='"form_value"' onClick='document.forms[0].action=\""form_action"\"+document.forms[0].Text.value;document.forms[0].submit();' /></td></tr>")
-)
-
-
-;; @syntax (Dragonfly:form_hidden <form_name> <form_value>)
-;; @param <form_name> a string containing the name for the hidden field
-;; @param <form_value> a string containing the value for the hidden field
-;; <p>Writes a standard form hidden field.</p>
-;; 
-(define (form-hidden form_name form_value)
-  (print "<input type='hidden' name='"form_name"' value='"form_value"' />")
-)
-
-;; @syntax (Dragonfly:form_close)
-;; <p>Writes a form close tag</p>
-;; 
-(define (form-close)
-  (print "</form></table>")
-)
-
-;; @syntax (Dragonfly:form_generate-from-columns <tablename>)
-;; <p>Generates a form including input field from the given table.
-;; The form uses POST Method and refers to itself. It includes one hidden
-;; field called dragonfly_form, to detect form submit.
-;; </p>
-;; 
-(define (form-generate-from-columns database tablename)
-  (Dragonfly:load-database database) ; load the specified nldb
-  (set 'columns (nldb:list-columns tablename))
-  (print "<table><form id='form_"table"' action='?"viewname"/"{save}"' method='POST'>")
-	(dolist (column_name columns)
-		(print "<tr class='form_row'><td class='form_label'><label for='"column_name"'>"column_name"</label></td><td class='form_input'><input id='"column_name"' name='"column_name"' size='30' type='text' /></td></tr>")
-	)
-  (print "<tr class='form_row'><td class='form_label'>&nbsp;</td><td class='form_input'><input id='form_submit' type='submit' name='commit' value='Add' /></td></tr>")
-  (print "<input type='hidden' name='databasetable' value='"table"' />")
-  (print "</form></table>")
-)
-
-(context Dragonfly)

example-site/dragonfly-framework/plugins-inactive/form.lsp

+;; @module form.lsp 
+;; @description A library for creating HTML forms
+;; @version 1.0 - Partial rewrite for Dragonfly. Addition attachments, custom port and proper utf8 encoding for subject/message/attachments
+;; @author Marc Hildmann 2009-2010
+
+(context 'FORM)
+
+;===============================================================================
+; !Form Functions
+;===============================================================================
+
+;; @syntax (FORM:open <form_action> <form_method)
+;; @param <name> a string containing the form action
+;; @param <name> a string containing the form submit method POST/GET
+;; <p>Writes a standard HTML form open element</p>
+;; 
+(define (create form_action form_method)
+  (print "<form action=\""form_action"\" method=\""form_method"\">")
+)
+
+;; @syntax (Dragonfly:form_textfield <form_name>)
+;; @param <name> a string containing the text field name
+;; <p>Writes a standard form field with size '30'</p>
+;; 
+(define (form-textfield form_name)
+  (print "<tr class='form_row'><td class='form_label'><label for='"form_name"'>"(title-case form_name)"</label></td><td class='form_input'><input id='"form_name"' name='"form_name"' size='30' type='text' /></td></tr>")
+)
+
+;; @syntax (FORM:input <input_type> <input_value>)
+;; @param <input_type> a string containing the input type
+;; @param <input_value> a string containing the input value
+;; <p>Writes a standard form input element.</p>
+;; 
+(define (input input_type input_value, input_name)
+  (print "<input type=\""input_type"\" value=\""input_value"\" name=\""input_name"\" />")
+)
+
+;; @syntax (Dragonfly:form-submit-js <form_action> <form_value>)
+;; @param <form_action> a string containing the URI after submitting the submit button
+;; @param <form_value> a string containing the value for the submit button
+;; <p>Writes a form submit button with some javascript
+;; which modifies the action attribute.</p>
+;; 
+(define (form-submit-js form_action form_value)
+  (print "<tr class='form_row'><td class='form_label'>&nbsp;</td><td class='form_input'><input id='commit' type='button' value='"form_value"' onClick='document.forms[0].action=\""form_action"\"+document.forms[0].Text.value;document.forms[0].submit();' /></td></tr>")
+)
+
+;; @syntax (FORM:close)
+;; <p>Writes a form close tag</p>
+;; 
+(define (end)
+  (print "</form>")
+)
+
+;; @syntax (Dragonfly:form_generate-from-columns <tablename>)
+;; <p>Generates a form including input field from the given table.
+;; The form uses POST Method and refers to itself. It includes one hidden
+;; field called dragonfly_form, to detect form submit.
+;; </p>
+;; 
+(define (form-generate-from-columns database tablename)
+  (Dragonfly:load-database database) ; load the specified nldb
+  (set 'columns (nldb:list-columns tablename))
+  (print "<table><form id='form_"table"' action='?"viewname"/"{save}"' method='POST'>")
+	(dolist (column_name columns)
+		(print "<tr class='form_row'><td class='form_label'><label for='"column_name"'>"column_name"</label></td><td class='form_input'><input id='"column_name"' name='"column_name"' size='30' type='text' /></td></tr>")
+	)
+  (print "<tr class='form_row'><td class='form_label'>&nbsp;</td><td class='form_input'><input id='form_submit' type='submit' name='commit' value='Add' /></td></tr>")
+  (print "<input type='hidden' name='databasetable' value='"table"' />")
+  (print "</form></table>")
+)
+
+
+
+(context MAIN)

example-site/views/dragonfly_forms.html

+<% (display-partial "doctype") %>
+<head>
+	<%
+	(display-partial "header")
+	(script (web-root "includes/js/jquery-ui-1.7.2.custom.min.js"))
+	%>
+</head>
+
+<body>
+
+<div id="wrap">
+	<div id="header">
+		<% (display-partial "navigation") %>	
+		<div class="clear"></div>
+	</div>
+
+	<div id="content">
+				
+		<div class="title nomargin">
+			<p><% (title "| Dragonfly web framework") %><p>
+		</div>
+		
+		<h1>Parameters and Forms</h1>
+		<p class="extract">
+			Dragonfly's <b>lib/request.lsp</b> defines many of the global symbols needed to deal with getting user input from forms, handling file uploads, etc.
+		</p>
+		<p>
+			Dragonfly includes the PHP-like contexts <b>$GET</b>, <b>$POST</b>, <b>$COOKIES</b> and <b>$FILES</b> for handling user-supplied data.
+		</p>
+		<p>
+			For example, if we wanted to retrieve the value of the GET parameter "foo", we would write:
+		</p>
+		<pre class="textmate-source"><span class="source source_newlisp"><span class="entity entity_paren entity_paren_lisp">(</span><span class="entity entity_name entity_name_function entity_name_function_lisp">$GET</span> <span class="string string_quoted string_quoted_double string_quoted_double_lisp"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_lisp">"</span>foo<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_lisp">"</span></span><span class="entity entity_paren entity_paren_lisp">)</span></span></pre>
+		<p>
+			This box shows the value of "foo":
+		</p>
+		<div class="resultbox" id="foo-result"><%=($GET "foo")%></div>
+		<% (if-not ($GET "foo") (begin %>
+		<p>
+			It's currently <span class="code">nil</span> because no GET parameter "foo" has been set. Click <%(link_to "this link" (string DF_PAGE "?foo=bar"))%> to set its value to <span class="code">bar</span>.
+		</p>
+		<% ) %>
+		<script type="text/javascript" charset="utf-8">
+			$(document).ready(function() {
+				$('#foo-result').effect("highlight", {color:"#fdb2b5"}, 3000);
+			});
+		</script>
+		<% ) %>
+		<p>
+			For more information on <b>$GET</b>, <b>$POST</b>, <b>$COOKIES</b> and <b>$FILES</b>, see the <%(link_to "api" "dragonfly_api")%>.
+		</p>
+		<h2>Same Name Multi-Params</h2>
+		<p>
+			Although it's rare, sometimes it's convenient to generate a request where a single parameter has multiple values, like this:
+		</p>
+		<p><span class="code">GET /form.cgi?bar=1&bar=2</span></p>
+		<p>
+			However, normally only the last value of <span class="code">bar</span> is accepted. To get the entire list of values append <b>[]</b> to the end of the variable name, like this:
+		</p>
+		<p><span class="code">GET /form.cgi?bar[]=1&bar[]=2</span></p>
+		<pre class="textmate-source"><span class="source source_newlisp"><span class="entity entity_paren entity_paren_lisp">(</span><span class="entity entity_name entity_name_function entity_name_function_lisp">$GET</span> <span class="string string_quoted string_quoted_double string_quoted_double_lisp"><span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_begin punctuation_definition_string_begin_lisp">"</span>bar[]<span class="punctuation punctuation_definition punctuation_definition_string punctuation_definition_string_end punctuation_definition_string_end_lisp">"</span></span><span class="entity entity_paren entity_paren_lisp">)</span>
+<span class="comment comment_line comment_line_semicolon comment_line_semicolon_lisp"><span class="punctuation punctuation_definition punctuation_definition_comment punctuation_definition_comment_lisp">;</span>=&gt; (1 2)</span></span></pre>
+		<p>
+			One prominent example is a form that contains a select box that allows multiple selections. Like this one:
+		</p>
+		<h3 class="code">Example: Multi-selection form</h3>
+		<p>
+			Select multiple choices by holding down the <i>Shift</i> key and then click <b>Submit</b>.
+		</p>
+		<div style="width:200px; margin-top: 10px">
+			<a name="multi"></a>
+			
+			<% 			
+			(DF:activate-plugin "form")
+			(FORM:create (string DF_PAGE "#multi") "POST")			
+			%>
+			
+			<select name="foo[]" multiple="yes" style="width:100%">
+				<option value="option1">option1</option>
+				<option value="option2">option2</option>
+				<option value="option3">option3</option>
+			</select>
+			
+			<div style="float:right">
+				<%
+				(FORM:input "reset" "Deselect", "reset1")
+				(FORM:input "submit" "Submit", "submit1")
+				(FORM:input "hidden" "", "hidden1")
+				(FORM:input "hidden" "", "hidden2")
+				%>
+			</div>
+			<div class="clear"></div>
+			
+			<%
+			(FORM:end)
+			%>
+
+		</div>
+		
+		<% (when ($POST "foo[]") %>
+		<p>Value of <span class="code"><b>($POST "foo[]")</b></span>:</p>
+		<p><span class="code"><%=($POST "foo[]")%></span></p>
+		<%)%>
+		
+		<% (display-partial "continue") %>
+		
+		<div class="line-dotted"></div>
+
+		<% (benchmark-result) %>
+		
+		<div class="line-dotted"></div>
+		
+		
+	</div><!-- END CONTENT -->
+	
+</div><!-- END WRAP -->
+<% (display-partial "footer") %>
+