Permalink
Browse files

cleaned up docs, examples

  • Loading branch information...
1 parent 0a87cd0 commit 4385598277f27973a8e64e0a4f40f569da687760 Michael Botsko committed Sep 23, 2009
Showing with 124 additions and 92 deletions.
  1. +3 −3 README
  2. +120 −85 docs/DOCUMENTATION
  3. +1 −4 example-html.php
View
6 README
@@ -1,9 +1,9 @@
The jquery.Formbuilder plugin is a script that allows you integrate
a jquery and php based form-creation tool into your application.
-The interface is built by the jquery plugin based off of xml provided
-from the server. The php component class assists you with storing the data,
-generating the xml, and generating the html form.
+The interface is built by the jquery plugin based off of an xml response provided
+by the server. The php class assists you with storing the data,
+generating the xml, generating the html form, and processing the data.
Please feel free to file issues at http://github.com/botskonet/jquery.formbuilder/issues
Please feel free to fork the project and provide patches back.
View
@@ -1,85 +1,120 @@
-Formbuilder Docs
-
-
-
-The request comes in as POST so that we can maintain characters like newlines, etc. PHP receives
-an array because of the serialization, which you can immediate through.
-
-If you want, you can just store this serialized string to a single database field with a hash or
-some security and the just unserialize it. No need to create dynamic tables or anything.
-
-
-print_r($_POST);
-
- Array
-(
- [ul] => Array
- (
- [0] => Array
- (
- [class] => input_text
- [required] => false
- [values] => Name
- )
-
- [1] => Array
- (
- [class] => input_text
- [required] => true
- [values] => E-mail Address?
- )
-
- [2] => Array
- (
- [class] => checkbox
- [required] => false
- [title] => Choose any:
- [values] => Array
- (
- [2] => Array
- (
- [value] => PHP
- [default] => true
- )
-
- [3] => Array
- (
- [value] => jQuery
- [default] => true
- )
-
- [4] => Array
- (
- [value] => XML
- [default] => true
- )
-
- [5] => Array
- (
- [value] => Aspen
- [default] => false
- )
- )
- )
- [3] => Array
- (
- [class] => radio
- [required] => true
- [title] => Choose one:
- [values] => Array
- (
- [2] => Array
- (
- [value] => Yes
- [default] => true
- )
-
- [3] => Array
- (
- [value] => No
- [default] => false
- )
- )
- )
- )
-)
+HOW TO USE FORMBUILDER
+===========================================================
+
+The files we've setup in this package are designed to assist
+you in understanding / working with this system. We've explained
+a bit more details in this document. Please let us know
+if anything needs to be corrected.
+
+
+
+Including Javascript
+------------------------------------------
+
+The first step is to include the proper javascript files.
+
+ <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
+ <script type="text/javascript" src="js/jquery.scrollTo-min.js"></script>
+ <script type="text/javascript" src="js/jquery.formbuilder.js"></script>
+
+
+Then, you need to activate the form builder class on a single div within your page.
+
+The save url is the relative/absolute to which the POST data should be sent when
+the user activates the save process.
+
+The load url is the relative/absolute address that will provide the xml response
+for loading.
+
+ <script type="text/javascript">
+ $(document).ready(function(){
+ $('#form-builder').formbuilder({
+ 'save_url': 'example-save.php',
+ 'load_url': 'example-load.php'
+ });
+ });
+ </script>
+
+
+
+Including / Using PHP Class
+------------------------------------------
+
+The first step in your application is to include the class:
+
+ require('Formbuilder/Formbuilder.php');
+
+The class is independent of any database so you need to handle saving the form
+structure/hash, as well as storing/emailing the live form submission.
+
+
+
+ Saving Jquery Form
+ --------------------------------
+
+To save the POST request from the jquery object, just invoke the following:
+
+ // Get the POST data.
+ $form_data = isset($_POST['ul']) ? $_POST['ul'] : false;
+
+ // Pass the data to the class
+ $form = new Formbuilder($form_data);
+
+ // Return the array for saving to a database
+ $for_db = $form->store();
+
+The $for_db variable is an array and will contain a hash value, and the
+serialized form value. Save these two values to your database. They both need
+to be provided to the class for rendering/processing the form in the same array
+format.
+
+
+
+ Loading for Jquery Form
+ --------------------------------
+
+The jquery plugin is awaiting for xml, so by calling the following methods
+you will generate the right xml. You need to pass the hash and form structure
+saved in your database as an array, just as it was saved.
+
+ $form = new Formbuilder($fake_db_vals);
+ $form->render_xml();
+
+
+
+ Render Form HTML
+ --------------------------------
+
+To render the actual form html for users/visitors to fill out, you
+need to provide the hash/structure array (same as previous section) to the
+following methods.
+
+ $form = new Formbuilder($fake_db_vals);
+ $form->render_html('example-submit.php');
+
+The render html function will generate and print the html of the entire form.
+By default the css should be very flexible for your display needs, but you
+may always extend the formbuilder class to provide your own output logic.
+
+The argument to the render_html function is the action for the form. It may be a
+relative or absolute URL.
+
+
+
+ Process Form Submission
+ --------------------------------
+
+When the user fills out the form, we will try to validate it as best as we can
+and then we'll provide success/failure along with an array of the results.
+
+Again, you must pass the hash/form structure array to the formbuilder class.
+
+ $form = new Formbuilder($fake_db_vals);
+ $results = $form->process();
+
+The process function will check all fields for any basic validation. The returned
+array will include a boolean indicator for success/failure, an html unordered list
+of any validation errors, and an array of all valid results.
+
+You may use this array in constructing your email, saving back to a database,
+etc.
View
@@ -15,10 +15,7 @@
// form_structure and hash from our database. This is
// how the form data would have been saved using
// the $form->store() method.
-$fake_db_vals = array(
- 'form_hash'=>'bb7d5c1fa425235aa666c1a78b3873e7732709af',
- 'form_structure'=>'a:4:{i:0;a:3:{s:5:"class";s:10:"input_text";s:8:"required";s:5:"false";s:6:"values";s:4:"Name";}i:1;a:3:{s:5:"class";s:10:"input_text";s:8:"required";s:4:"true";s:6:"values";s:15:"E-mail Address?";}i:2;a:4:{s:5:"class";s:8:"checkbox";s:8:"required";s:5:"false";s:5:"title";s:11:"Choose any:";s:6:"values";a:4:{i:2;a:2:{s:5:"value";s:3:"PHP";s:7:"default";s:4:"true";}i:3;a:2:{s:5:"value";s:6:"jQuery";s:7:"default";s:4:"true";}i:4;a:2:{s:5:"value";s:3:"XML";s:7:"default";s:4:"true";}i:5;a:2:{s:5:"value";s:5:"Aspen";s:7:"default";s:5:"false";}}}i:3;a:4:{s:5:"class";s:5:"radio";s:8:"required";s:4:"true";s:5:"title";s:11:"Choose one:";s:6:"values";a:2:{i:2;a:2:{s:5:"value";s:3:"Yes";s:7:"default";s:4:"true";}i:3;a:2:{s:5:"value";s:2:"No";s:7:"default";s:5:"false";}}}}');
-
+include('fake-form-db-vals.php');
$form = new Formbuilder($fake_db_vals);
$form->render_html('example-submit.php');

0 comments on commit 4385598

Please sign in to comment.