ApPHP DataForm - Example of Code (Sample 1)

Show Plain Text »
  1. <?php
  2.  
  3. ## +---------------------------------------------------------------------------+
  4. ## | 1. Creating & Calling:                                                    |
  5. ## +---------------------------------------------------------------------------+
  6. ##  *** define a relative (virtual) path to dataform.class.php file
  7. ##  *** (relatively to the current file)
  8. ##  *** RELATIVE PATH ONLY ***
  9. define("DATAFORM_DIR", "");    /* Ex.: "dataform/" */
  10. require_once(DATAFORM_DIR."dataform.class.php");
  11.  
  12. ##  *** set needed options and create a new class instance
  13. $debug_mode = false;              /* display SQL statements while processing */    
  14. $messaging = true;                /* display system messages on a screen */
  15. $unique_prefix = "abc_";          /* prevent overlays - must be started with a letter */
  16. $dform = new DataForm($debug_mode, $messaging, $unique_prefix);
  17.  
  18. ##  *** creating variables that we need for database connection
  19. $DB_USER="db_user";
  20. $DB_PASS="db_password";    
  21. $DB_HOST="dsn";      
  22. $DB_NAME="db_name";          
  23.  
  24. ##  *** set data source with needed options
  25. $dform->DataSource("PDO", "mysql", $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS);                
  26.  
  27. ## +---------------------------------------------------------------------------+
  28. ## | 2. General Settings:                                                      |
  29. ## +---------------------------------------------------------------------------+
  30. ## +-- Modes & operations -----------------------------------------------------+
  31. ##  *** set modes
  32. $modes = array(
  33.     "add" =>true,
  34.     "insert" =>true,
  35.     "preview" =>true,
  36.     "edit" =>false
  37. );
  38. $dform->SetModes($modes);    
  39. ##  *** define using of Captcha    
  40. $df_captcha = true;
  41. $df_captcha_type = "standard";
  42. $dform->SetCaptcha($df_captcha, $df_captcha_type);
  43. ##  *** define mode after successful insertion - ""|"add"
  44. $df_mode_after_insert = "add";
  45. $dform->SetModeAfterInsert($df_mode_after_insert);
  46. $df_allow_templates = true;
  47. $dform->AllowTemplates($df_allow_templates);
  48.  
  49. $add_mode_template = '
  50. <p><span style="color:#cd0000">*</span> Items marked with an asterisk are required</p>
  51. <fieldset class="personal_info">
  52.    <legend>Personal Information</legend>        
  53.    <div class="notes">
  54.        <h4>Personal Information</h4>
  55.        <p>Please enter your name and address as they are listed for your debit card, credit card, or bank account.</p>
  56.    </div>
  57.    <div class="required"><label>@first_name@ :</label>{first_name}</div>
  58.    <div class="required"><label>@last_name@ :</label>{last_name}</div>
  59.    <div class="optional"><label>@address_1@ :</label>{address_1} {address_2}</div>
  60.    <div class="optional"><label>@city@ :</label>{city}</div>
  61.    <div class="optional"><label>@state@ :</label>{state}</div>
  62.    <div class="optional"><label>@postal@ :</label>{postal}</div>
  63.    <div class="required"><label>@country@ :</label>{country}</div>
  64. </fieldset>        
  65. <fieldset class="contact_info">
  66.    <legend>Contact Information</legend>
  67.    <div class="notes">
  68.        <h4>Contact Information</h4>
  69.        <p>Please enter your full email address, for example, <strong>name@domain.com</strong></p>
  70.        <p>It is important that you provide a valid, working email address that you have access to as it must be verified before you can use your account.</p>
  71.        <p>Please enter a land line number, not a mobile phone number.</p>
  72.    </div>
  73.    <div class="required"><label>@email@ :</label>{email}<small>We will never sell or disclose your email address to anyone.</small></div>
  74.    <div class="required"><label>@validator_email@ :</label>{validator_email}<small>Must match the email address you just entered above.</small></div>
  75.    <div class="required"><label>@phone@ :</label>{phone}</div>
  76.    <div class="optional"><label>@fax@ :</label>{fax}</div>
  77. </fieldset>
  78. <fieldset class="special_info">
  79.    <legend>Special Information</legend>        
  80.    <div class="notes">
  81.        <h4>Special Information</h4>
  82.        <p>Please enter a special information, related to your profile.</p>
  83.    </div>
  84.    <div class="optional"><label>@message@:</label>{message}<small>Must be 250 characters or less.</small></div>
  85.    <div class="optional"><label>@avatar@:</label>{avatar}</div>
  86.    <div class="required"><label>@availability@:</label>{availability}<small>Use the <kbd>CTRL</kbd> key to select more than one.</small></div>
  87. </fieldset>        
  88. <fieldset class="login_info">
  89.    <legend>Login Information</legend>        
  90.    <div class="notes">
  91.        <h4>Login Information</h4>
  92.        <p>Your username and password must both be at least 6 characters long and are case-sensitive. Please do not enter accented characters.</p>
  93.        <p>We recommend that your password is not a word you can find in the dictionary, includes both capital and lower case letters, and contains at least one special character (1-9, !, *, _, etc.).</p>
  94.    </div>
  95.    <div class="required"><label>@username@:</label>{username}<small>May only contain letters, numbers, underscore (_) and 6-20 characters long.</small></div>
  96.    <div class="required"><label>@password@:</label>{password}<small>Must be 6-25 characters long.</small></div>
  97.    <div class="required"><label>@validator_password@:</label>{validator_password}<small>Must match the password you entered just above.</small></div>
  98. </fieldset>
  99. <fieldset class="verification_info">
  100.    <legend>Verification</legend>
  101.    <div class="notes">
  102.        <h4>Verification Information</h4>
  103.        <p class=description>Type the characters you see in this picture. This ensures that a person, not an automated program, is creating this account.</p>
  104.    </div>
  105.    <div class="captcha">[CAPTCHA]</div>
  106.    <div class="terms"><br />{delimiter_1}<br /></div>            
  107. </fieldset>
  108. <fieldset>
  109.    <div class="submit">            
  110.        [CANCEL] &nbsp;&nbsp;&nbsp; [ADD]            
  111.    </div>
  112. </fieldset>
  113. ';
  114.  
  115. $preview_mode_template = '
  116. <fieldset class="personal_info">
  117.    <legend>Personal Information</legend>
  118.    <div class="preview"><label>@first_name@ :</label>{first_name}</div>
  119.    <div class="preview"><label>@last_name@ :</label>{last_name}</div>
  120.    <div class="preview"><label>@address_1@ :</label>{address_1} {address_2}</div>
  121.    <div class="preview"><label>@city@ :</label>{city}</div>
  122.    <div class="preview"><label>@state@ :</label>{state}</div>
  123.    <div class="preview"><label>@postal@ :</label>{postal}</div>
  124.    <div class="preview"><label>@country@ :</label>{country}</div>
  125. </fieldset>
  126. <fieldset class="personal_info">
  127.    <legend>Contact Information</legend>        
  128.    <div class="preview"><label>@email@ :</label>{email}</div>
  129.    <div class="preview"><label>@phone@ :</label>{phone}</div>
  130.    <div class="preview"><label>@fax@ :</label>{fax}</div>
  131. </fieldset>
  132. <fieldset class="special_info">
  133.    <legend>Special Information</legend>        
  134.    <div class="preview"><label>@message@ :</label>{message}</div>
  135.    <div class="preview"><label>@avatar@ :</label>{avatar}</div>
  136.    <div class="preview"><label>@availability@ :</label>{availability}</div>
  137. </fieldset>
  138. <fieldset class="login_info">
  139.    <legend>Login Information</legend>
  140.    <div class="preview"><label>@username@ :</label>{username}</div>
  141. </fieldset>
  142. <fieldset>
  143.    <div class="submit">
  144.        [CANCEL] &nbsp;&nbsp;&nbsp; [EDIT] &nbsp;&nbsp;&nbsp; [CREATE]
  145.    </div>
  146. </fieldset>
  147. ';
  148. $dform->SetTemplates($add_mode_template, $preview_mode_template);    
  149. ##  *** set CSS class for dataform
  150. ##  *** "default|blue|gray|green|pink|empty|x-blue|x-gray|custom" or your own css style
  151. $css_class = "custom";
  152. $dform->SetCssClass($css_class);
  153. ##  *** set DataForm caption
  154. $df_caption = "DataForm - Sample 1";
  155. $dform->SetCaption($df_caption);
  156. ##  *** set javascript error settings
  157. ##  *** display style - "all|each (default)"
  158. ##  *** errors container - "div|popup  (default)"
  159. $df_js_display_style = "all";
  160. $df_js_container = "popup";
  161. $dform->SetJsErrorsSettings(array("display_style"=>$df_js_display_style, "container"=>$df_js_container));
  162.      
  163. ## +---------------------------------------------------------------------------+
  164. ## | 3. Modes Settings:                                                         |
  165. ## +---------------------------------------------------------------------------+
  166. ##  *** set Add Mode table properties (% or px)
  167. $am_table_properties = array("width"=>"710px");
  168. $dform->SetAddModeTableProperties($am_table_properties);
  169. ##  *** set Preview Mode table properties (% or px)
  170. $pm_table_properties = array("width"=>"700px");
  171. $dform->SetPreviewModeTableProperties($pm_table_properties);
  172. ##  ***  set settings for Add/Insert modes
  173. $table_name  = "demo_customers";
  174. $primary_key = "id";
  175. $condition   = "";
  176. $dform->SetTable($table_name, $primary_key, $condition);
  177. ##  *** set columns in Add/Insert mode  
  178. $fill_from_array_availability = array("Part-time"=>"Part-time", "Full-time (Days)"=>"Full-time (Days)", "Full-time (Swing)"=>"Full-time (Swing)", "Full-time (Graveyard)"=>"Full-time (Graveyard)", "Weekends Only"=>"Weekends Only");
  179.  
  180. $am_columns = array(
  181.    "first_name"  =>array("header"=>"First Name", "type"=>"textbox", "req_type"=>"ry", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  182.    "last_name"   =>array("header"=>"Last Name", "type"=>"textbox", "req_type"=>"ry", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  183.    "address_1"   =>array("header"=>"Address", "type"=>"textbox", "req_type"=>"sy", "width"=>"120px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  184.    "address_2"   =>array("header"=>"", "type"=>"textbox", "req_type"=>"sy", "width"=>"75px", "title"=>"Addrees (line 2)", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  185.    "city"        =>array("header"=>"City", "type"=>"textbox", "req_type"=>"sy", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  186.    "state"       =>array("header"=>"State/Province", "type"=>"textbox", "req_type"=>"sy", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  187.    "postal"      =>array("header"=>"Zip/Postal Code", "type"=>"textbox", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  188.    "country"     =>array("header"=>"Country", "type"=>"textbox","req_type"=>"rt", "width"=>"210px", "title"=>"", "readonly"=>"false", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "autocomplete"=>"true", "handler"=>"modules/autosuggest/test.php", "maxresults"=>"12", "shownoresults"=>"false", "post_addition"=>"<br><small>start typing to see autocomplete in work</small>"),
  189.  
  190.    "email"       =>array("header"=>"Email", "type"=>"textbox", "req_type"=>"re", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  191.    "validator_email" =>array("header"=>"Re-enter Email", "type"=>"validator", "req_type"=>"rv", "width"=>"210px", "title"=>"Confirm Email", "readonly"=>"false", "maxlength"=>"50", "default"=>"", "visible"=>"true", "on_js_event"=>"", "for_field"=>"email", "validation_type"=>"email"),
  192.    "phone"       =>array("header"=>"Phone", "type"=>"textbox", "req_type"=>"rx", "template"=>"(ddd)-ddd-dd-dd", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  193.    "fax"         =>array("header"=>"Fax", "type"=>"textbox", "req_type"=>"st", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  194.    
  195.    "message"     =>array("header"=>"Your Message", "type"=>"textarea", "req_type"=>"st", "width"=>"175px", "title"=>"", "readonly"=>"false", "maxlength"=>"250", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "edit_type"=>"simple", "resizable"=>"true", "rows"=>"3", "cols"=>"1"),
  196.    "avatar"      =>array("header"=>"Avatar", "type"=>"image", "req_type"=>"st", "width"=>"190px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"uploads/", "max_file_size"=>"300K", "image_width"=>"120px", "image_height"=>"90px", "resize_image"=>"false", "resize_width"=>"", "resize_height"=>"", "magnify"=>"false", "magnify_type"=>"lightbox", "magnify_power"=>"2", "file_name"=>"", "host"=>"local"),
  197.    "availability" =>array("header"=>"What is your current availability?", "type"=>"enum", "req_type"=>"rt", "width"=>"210px", "title"=>"Current Availability", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "source"=>$fill_from_array_availability, "view_type"=>"dropdownlist", "radiobuttons_alignment"=>"horizontal|vertical", "multiple"=>"true", "multiple_size"=>"3"),
  198.    
  199.    "username"    =>array("header"=>"Username", "type"=>"textbox", "req_type"=>"rl", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"20", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>""),
  200.    "password"    =>array("header"=>"Password", "type"=>"password", "req_type"=>"rp", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"25", "default"=>"", "unique"=>false, "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "hide"=>true),
  201.    "validator_password" =>array("header"=>"Please re-enter your password", "type"=>"validator", "req_type"=>"rv", "width"=>"210px", "title"=>"Confirm Password", "readonly"=>"false", "maxlength"=>"50", "default"=>"", "visible"=>"true", "on_js_event"=>"", "for_field"=>"password", "validation_type"=>"password"),
  202.    
  203.    "delimiter_1" =>array("inner_html"=>"<input type="checkbox" value="1" name="rcy__nc" title="Terms and Conditions" /> I have read and AGREE with Terms & Conditions"),
  204. );
  205. $dform->SetColumns($am_columns);
  206.  
  207. ## +---------------------------------------------------------------------------+
  208. ## | 4. Bind the DataForm:                                                     |
  209. ## +---------------------------------------------------------------------------+
  210. ##  *** bind the DataForm and draw it on the screen
  211. $dform->Bind();      
  212.  
  213. ?>