- Timestamp:
- 12/28/11 04:23:43 (5 months ago)
- Location:
- trunk/inc
- Files:
-
- 1 added
- 2 edited
-
classes/BxDolForm.php (modified) (4 diffs)
-
classes/BxDolFormQuery.php (added)
-
js/jquery.webForms.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/inc/classes/BxDolForm.php
r15793 r15798 21 21 22 22 /** 23 * Forms base class, consists of: 24 * - automatic check routines 25 * - get clear variables from input routines 26 * - database insert/update routines 27 * 28 * Init form object examples: 23 * Forms allows to display forms from data stored in DB tables, before it was possible to display forms from PHP arrays only. 24 * 25 * 26 * The Form Objects have the following main advantages: 27 * - Minimal coding is needed to create different forms 28 * - Easy forms alterations 29 * - Multiple representations of the same form 30 * - Automated data inserting into database 31 * - Automated data updating 32 * - Automated data checking 33 * - Automatic security checking 34 * - Automatic spam filter 35 * 36 * 37 * Forms API uses several definitions: 38 * - Form or Form Object - record in sys_objects_form table, or instance of Form class. 39 * - Form Display - set of some form inputs in particular order, displayed for some purpose; one form can have several displays, for example add and edit displays. 40 * - Form Input or Form Field - form input field, like textarea, checkbox or set of radio buttons. 41 * 42 * 43 * @section form_creating_object Creating the Form Object 44 * 45 * 1. Create Form Object, add record to sys_objects_form table: 46 * - object - name of the Form Object, in the format: vendor prefix, underscore, module prefix, underscore, internal identifier or nothing; for example: bx_group - for group data processing, like group adding or editing. 47 * - title - Form Object title to display in studio forms builder. 48 * - action - url to submit form to, if url is not full and not empty, then site url is added automatically. 49 * - form_attrs - serialized array of additional form attributes. 50 * - submit_name - name of form field with submit button, it is used to determine if form is submitted. 51 * - table - DB table name (for automatic saving/updating). 52 * - key - DB table field with unique ID (for automatic updating). 53 * - uri - DB table field with URI (for automatic URI generation, aling with uri_title). 54 * - uri_title - DB table field with data title (for automatic URI generation, aling with uri). 55 * - params - serialized array of additional form parameters: 56 * - checker_helper - name of custom BxDolFormCheckerHelper class. 57 * - csrf - array of Cross-site request forgery attack prevention parameters, for now only one boolean parameter is supported - disabled, so it can be disabled for particular form. 58 * - active - 1 or 0, if form is inactive then it can not be used anywhere. 59 * - override_class_name - user defined class name which is derived from BxTemplFormView. 60 * - override_class_file - the location of the user defined class, leave it empty if class is located in system folders. 61 * 62 * 63 * 2. Create Form Displays, add records to sys_form_displays table: 64 * - display_name - name of the Form Display, in the format: 65 * form object name, underscore, internal identifier or nothing; 66 * for example: bx_group_add - for displaying group adding form, bx_group_edit - for displaying group editing form 67 * - module - module name this display belongs to, it must be associated with name field in sys_modules table. 68 * - object - form object name from sys_objects_form table this Form Display belongs to. 69 * - title - Form Display title to display in studio forms builder. 70 * 71 * 72 * 3. Create Form Fields, add records to sys_form_inputs table: 73 * - object - form object name from sys_objects_form table this Form Field belongs to. 74 * - name - unique Form Field name in particular From Object. 75 * - value - default value, or empty if there is no default value. 76 * - values - possible values, for certain form field types. 77 * - checked - 0 or 1, it determines if form field is checked, for certain form field types. 78 * - type - form field type, for now the following types are supported: 79 * - text - text input field. 80 * - password - password input field. 81 * - textarea - multiline input field. 82 * - number - number input field. 83 * - select - select one from all available values. 84 * - select_multiple - select one, multiple or all items from all available values. 85 * - switcher - on/off switcher. 86 * - checkbox - one checkbox. 87 * - checkbox_set - set of checkboxes. 88 * - radio_set - set of radio buttons. 89 * - slider - select some numeric value within the range using slider control. 90 * - doublerange - select range values within the range using slider control. 91 * - datepicker - date selection control. 92 * - datetime - date/time selection control. 93 * - captcha - image captcha. 94 * - hidden - hidden input field. 95 * - file - file upload input. 96 * - button - button control. 97 * - image - form image button. 98 * - reset - form reset button. 99 * - submit - form submit button. 100 * - value - just displaying value without any crontol. 101 * - block_header - start group of field. 102 * - custom - custom control. 103 * - input_set - set of other form controls. 104 * detailed description of every type will be described below. 105 * - caption - input title. 106 * - info - some info to help user to input data into the field, it's better to specify format and limits here. 107 * - required - indicate that the input is required by displaying asterisk near the field, 108 * please note that this field don't perform any checking automatically, 109 * since you mark field as required you need to specify checked function which will check entered value. 110 * - collapsed - display section as collapsed by default, for block_header field type only. 111 * - html - display visual editor of certain type, for textarea field type only. 112 * - 0 - no visual editor, leave textarea field as it is. 113 * - 1 - micro visual editor. 114 * - 2 - default visual editor. 115 * - 3 - mini visual editor. 116 * - attrs - serialized array of additional input attributes. 117 * - attrs_tr - serialized array of additional attributes for the whole input row. 118 * - attrs_wrapper - serialized array of additional attributes for input wrapper. 119 * - checker_func - checked function, if you marked field as required in textarea field you need to point one of the following checked functions: 120 * - Length - check value length, additional params must contain min and/or max values for checking. 121 * - Date - check if date is entered correctly. 122 * - DateTime - check if datetime is entered correctly. 123 * - Preg - check value with provided regular expression in checker_params field. 124 * - Avail - just check if value isn't 0 or empty string, additional function parameters are not used. 125 * - Email - check if value is written in valid email format. 126 * - Captcha - check if captcha is entered correctly, for captcha field type only. 127 * You can inherit BxDolFormCheckerHelper class and add own checker functions, you will need to point your custom class in Form Object params array. 128 * - checker_params - serialized array of checker_func parameters. 129 * - checker_error - error message to show in case of checking function returns false. 130 * - db_pass - function to pass value through before saving to database and after restoring from database (for example when date need to be converted from/to timestamp value), 131 * available values are the following: 132 * - Int - convert value to integer. 133 * - Float - convert value to floating point number. 134 * - Date - convert value to timestamp value before saving to database, and convert from timespamp value after restoring from database. 135 * - DateTime - convert value to timestamp value before saving to database, and convert from timespamp value after restoring from database. 136 * - Xss - it warns you that this text can contain XSS vulnerabilities and you need to be extra careful with this, and always use Forms engine to output string to the browser or use bx_process_output if going to output text manually. 137 * - XssHtml - this text cam have HTML tags, so perform XSS vulnerabilies cleaning before saving to database. 138 * - All - do not perform any conversion and pass text as it is, be careful with this, use it only when no other function can be used, and make all necessary security checking by yourself. 139 * - Preg - perform regular expression on the text before saving data to database, regular expression can be provided in db_params field. 140 * - Tags - tags are validated and correctly joined using delimiter symbol. 141 * - Categories - categories are validated and correctly joined using delimiter symbol. 142 * - Boolean - this is used for checkboxes with 'on' value which need to be converted into boolean value. 143 * - Set - convert set of values into bit integer before saving to database, and restore bit integer into array of values upon restoration from database, it can be used for select_multiple and checkbox_set field types. 144 * Please note that values for this field must be 1,2,4,8,... (values of power of 2); the max number of values are 31 for 32bit hardware and 63 for 64bit hardware. 145 * You can inherit BxDolFormCheckerHelper class and add own pass functions, you will need to point your custom class in Form Object params array. 146 * - db_params - serialized array of db_pass parameters. 147 * 148 * 149 * 4. Add Form Fields and Form Displays associations, add records to sys_form_display_inputs table: 150 * - display_name - name of the Form Display from sys_form_displays table. 151 * - input_name - name of the Form Field from sys_form_inputs table. 152 * - hidden_for_levels - bit field with set of member level ids. To use member level id in bit field the level id minus 1 is used as power of 2, for example: 153 * - user level id = 1 -> 2^(1-1) = 1 154 * - user level id = 2 -> 2^(2-1) = 2 155 * - user level id = 3 -> 2^(3-1) = 4 156 * - user level id = 4 -> 2^(4-1) = 8 157 * - active - 1 - form field displayed on form, or 0 - isn't displayed. 158 * - order - fields are displayed in this order. 159 * 160 * 161 * @section form_field_types Form Field Types 162 * 163 * Detailed description of Form Field Types. 164 * 165 * Almost all fields have the following common parameters: 166 * - object 167 * - name 168 * - type 169 * - caption 170 * - info 171 * - required 172 * - attrs 173 * - attrs_tr 174 * - attrs_wrapper 175 * 176 * We will not describe above list of parameters in every type, since they work the same way for all types. 177 * 178 * The list below are field types with their unique parameters, which are designed especially for this field, or some parameters which work differently for the specified field type. 179 * 180 * text - text input field. It is displayed as regular single line text input. 181 * Parameters: 182 * - value - default value, or empty if there is no default value. 183 * - values - not applicable here. 184 * - checked - not applicable here. 185 * - collapsed - not applicable here. 186 * - html - not applicable here. 187 * - checker_func 188 * Can be used here: Length, Preg, Avail, Email 189 * Make no sense to use it here: Date, DateTime, Captcha 190 * - db_pass 191 * Can be used here: Int, Float, Xss, All, Preg, Tags, Categories 192 * Make no sense to use it here: Date, DateTime, XssHtml, Boolean, Set 193 * 194 * password - password input field. It is displayed as HTML input element with invisible input. 195 * Parameters: 196 * - value - default value, or empty if there is no default value. 197 * - values - not applicable here. 198 * - checked - not applicable here. 199 * - collapsed - not applicable here. 200 * - html - not applicable here. 201 * - checker_func 202 * Can be used here: Length, Preg, Avail. 203 * Make no sense to use it here: Date, DateTime, Captcha, Email. 204 * - db_pass 205 * Can be used here: Xss, All. 206 * Make no sense to use it here: Int, Float, Date, DateTime, XssHtml, Boolean, Set, Preg, Tags, Categories. 207 * 208 * textarea - multiline input field. It can be displayed as regular textarea field or as visual HTML editor. 209 * Parameters: 210 * - value - default value, or empty if there is no default value. 211 * - values - not applicable here. 212 * - checked - not applicable here. 213 * - collapsed - not applicable here. 214 * - html - use visual editor or not. 215 * - 0 - no visual editor, leave textarea field as it is. 216 * - 1 - micro visual editor. 217 * - 2 - default visual editor. 218 * - 3 - mini visual editor. 219 * - checker_func 220 * Can be used here: Length, Preg, Avail 221 * Make no sense to use it here: Email, Date, DateTime, Captcha 222 * - db_pass 223 * Can be used here: Int, Float, Xss, XssHtml, All, Preg, Tags, Categories 224 * Make no sense to use it here: Date, DateTime, Boolean, Set 225 * 226 * number - number input field. It is displayed as HTL text input, but with limited width. Also some browsers can add additional controls to this field. 227 * Parameters: 228 * - value - default value, or empty if there is no default value. 229 * - values - not applicable here. 230 * - checked - not applicable here. 231 * - collapsed - not applicable here. 232 * - html - not applicable here. 233 * - checker_func 234 * Can be used here: Length, Preg, Avail 235 * Make no sense to use it here: Email, Date, DateTime, Captcha 236 * - db_pass 237 * Can be used here: Int, Float 238 * Make no sense to use it here: Xss, XssHtml, All, Preg, Tags, Categories, Date, DateTime, Boolean, Set 239 * 240 * select - select one from all available values. It is displayed as HTML combo-box. 241 * Parameters: 242 * - value - default value (array index of selected item from values array), or empty - if there is no default value. 243 * - values - serialized array of available values, or reference to predefined set of values. 244 * - checked - not applicable here. 245 * - collapsed - not applicable here. 246 * - html - not applicable here. 247 * - checker_func 248 * Can be used here: Length, Preg, Avail 249 * Make no sense to use it here: Email, Date, DateTime, Captcha 250 * - db_pass 251 * Can be used here: Int, Float, Xss, All, Preg 252 * Make no sense to use it here: Date, DateTime, Tags, Categories, XssHtml, Boolean, Set 253 * 254 * select_multiple - select one, multiple or all items from all available values. It is displayed as HTML multiple selection input. 255 * Parameters: 256 * - value - default value (bit integer of array indexes of selected items from values array), or empty - if there is no default value. 257 * - values - serialized array of available values, or reference to predefined set of values. Array index must be power of 2. Max number of values is 31 on 32bit hardware or 63 on 64bit hardware. 258 * - checked - not applicable here. 259 * - collapsed - not applicable here. 260 * - html - not applicable here. 261 * - checker_func 262 * Can be used here: Length, Preg, Avail 263 * Make no sense to use it here: Email, Date, DateTime, Captcha 264 * - db_pass 265 * Can be used here: Int 266 * Make no sense to use it here: Float, Xss, All, Preg, Date, DateTime, Tags, Categories, XssHtml, Boolean, Set 267 * 268 * switcher - on/off switcher. It is displayed as custom HTML element with own styles, but on background it works as regular HTML checkbox element. 269 * Parameters: 270 * - value - the value which will be submitted if switcher is on, if switcher is off - nothing is submitted. 271 * - values - not applicable here. 272 * - checked - if set to 1 then switcher is on by default, 0 - it is off by default. 273 * - collapsed - not applicable here. 274 * - html - not applicable here. 275 * - checker_func 276 * Can be used here: Length, Preg, Avail 277 * Make no sense to use it here: Email, Date, DateTime, Captcha 278 * - db_pass 279 * Can be used here: Int, Float, Xss, All, Preg, Boolean 280 * Make no sense to use it here: Date, DateTime, Tags, Categories, XssHtml, Set 281 * 282 * checkbox - one checkbox. Displayed as HTML checkbox input element. 283 * Parameters: 284 * - value - the value which will be submitted if checkbox is checked, if checkbox isn't checked - nothing is submitted. 285 * - values - not applicable here. 286 * - checked - if set to 1 then checkbox is checked by default, 0 - it is unchecked by default. 287 * - collapsed - not applicable here. 288 * - html - not applicable here. 289 * - checker_func 290 * Can be used here: Length, Preg, Avail 291 * Make no sense to use it here: Email, Date, DateTime, Captcha 292 * - db_pass 293 * Can be used here: Int, Float, Xss, All, Preg, Boolean 294 * Make no sense to use it here: Date, DateTime, Tags, Categories, XssHtml, Set 295 * 296 * checkbox_set - set of checkboxes. It is displayed as set of checkboxes. It is displayed in one row if number of items is equal or less than 3 or every item is displayed on new line if there is more than 3 items in the set. 297 * Parameters: 298 * - value - default value (bit integer of array indexes of selected items from values array), or empty - if there is no default value. 299 * - values - serialized array of available values, or reference to predefined set of values. Array index must be power of 2. Max number of values is 31 on 32bit hardware or 63 on 64bit hardware. 300 * - checked - not applicable here. 301 * - collapsed - not applicable here. 302 * - html - not applicable here. 303 * - checker_func 304 * Can be used here: Length, Preg, Avail 305 * Make no sense to use it here: Email, Date, DateTime, Captcha 306 * - db_pass 307 * Can be used here: Int 308 * Make no sense to use it here: Float, Xss, All, Preg, Date, DateTime, Tags, Categories, XssHtml, Boolean, Set 309 * 310 * radio_set - set of radio buttons. It is displayed as set of radio buttons. It is displayed in one row if number of items is equal or less than 3 or every item is displayed on new line if there is more than 3 items in the set. 311 * Parameters: 312 * - value - default value (array index of selected radio button from values array), or empty - if there is no default value. 313 * - values - serialized array of available values, or reference to predefined set of values. 314 * - checked - not applicable here. 315 * - collapsed - not applicable here. 316 * - html - not applicable here. 317 * - checker_func 318 * Can be used here: Length, Preg, Avail 319 * Make no sense to use it here: Email, Date, DateTime, Captcha 320 * - db_pass 321 * Can be used here: Int, Float, Xss, All, Preg 322 * Make no sense to use it here: Date, DateTime, Tags, Categories, XssHtml, Boolean, Set 323 * 324 * slider - select some numeric value within the range using slider control. It is displayed as jQuery UI HTML control, but on background it works as regular HTML text input element. 325 * Parameters: 326 * - value - default value in the format, or empty if there is no default value. 327 * - values - not applicable here. 328 * - checked - not applicable here. 329 * - collapsed - not applicable here. 330 * - html - not applicable here. 331 * - attrs - the following additional attributes can be used here: 332 * - min - minimal value, default is 0. 333 * - max - maximal value, default is 100. 334 * - step - value can be changed by this step only, default is 1. 335 * - checker_func 336 * Can be used here: Length, Avail 337 * Make no sense to use it here: Preg, Email, Date, DateTime, Captcha 338 * - db_pass 339 * Can be used here: Int, Float 340 * Make no sense to use it here: Xss, XssHtml, All, Preg, Tags, Categories, Date, DateTime, Boolean, Set 341 * 342 * doublerange - select range values within the range using slider control. 343 * Parameters: 344 * - value - default value in the format [min value]-[max value], for example 16-99, or empty if there is no default value. 345 * - values - not applicable here. 346 * - checked - not applicable here. 347 * - collapsed - not applicable here. 348 * - html - not applicable here. 349 * - attrs - the following additional attributes can be used here: 350 * - min - minimal value, default is 0. 351 * - max - maximal value, default is 100. 352 * - step - value can be changed by this step only, default is 1. 353 * - checker_func 354 * Can be used here: Length, Avail 355 * Make no sense to use it here: Preg, Email, Date, DateTime, Captcha 356 * - db_pass 357 * Can be used here: Xss, All, Preg 358 * Make no sense to use it here: Int, Float, XssHtml, Tags, Categories, Date, DateTime, Boolean, Set 359 * 360 * datepicker - date selection control. It is displayed as HTML text input control, when clicking on this input then popup with date selector control is appeared. 361 * Parameters: 362 * - value - default value, in the format YYYY-MMM-DD, or empty if there is no default value. 363 * - values - not applicable here. 364 * - checked - not applicable here. 365 * - collapsed - not applicable here. 366 * - html - not applicable here. 367 * - checker_func 368 * Can be used here: Date 369 * Make no sense to use it here: Length, Preg, Avail, Email, DateTime, Captcha 370 * - db_pass 371 * Can be used here: Date 372 * Make no sense to use it here: Int, Float, Xss, All, Preg, Tags, Categories, DateTime, XssHtml, Boolean, Set 373 * 374 * datetime - date/time selection control. 375 * Parameters: 376 * - value - default value, in the format YYYY-MMM-DD HH:MM:SS, or empty if there is no default value. 377 * - values - not applicable here. 378 * - checked - not applicable here. 379 * - collapsed - not applicable here. 380 * - html - not applicable here. 381 * - checker_func 382 * Can be used here: DateTime 383 * Make no sense to use it here: Length, Preg, Avail, Email, Date, Captcha 384 * - db_pass 385 * Can be used here: DateTime 386 * Make no sense to use it here: Int, Float, Xss, All, Preg, Tags, Categories, Date, XssHtml, Boolean, Set 387 * 388 * captcha - image captcha. Displayed as image with some text along with HTML text input for entering displayed on the image text. 389 * Parameters: 390 * - value - not applicable here. 391 * - values - not applicable here. 392 * - checked - not applicable here. 393 * - collapsed - not applicable here. 394 * - html - not applicable here. 395 * - checker_func 396 * Can be used here: Captcha 397 * Make no sense to use it here: Length, Preg, Avail, Email, Date, DateTime 398 * - db_pass 399 * Can be used here: Xss, All, Preg 400 * Make no sense to use it here: Int, Float, Tags, Categories, Date, DateTime, XssHtml, Boolean, Set 401 * 402 * hidden - hidden input field. Displayed as hidden HTML input. 403 * Parameters: 404 * - value - hidden input value. 405 * - values - not applicable here. 406 * - checked - not applicable here. 407 * - collapsed - not applicable here. 408 * - html - not applicable here. 409 * - checker_func 410 * Can be used here: Length, Preg, Avail, Email, Date, DateTime 411 * Make no sense to use it here: Captcha 412 * - db_pass 413 * Can be used here: Int, Float, Xss, All, Preg, Tags, Categories, Date, DateTime, XssHtml, Boolean 414 * Make no sense to use it here: Set 415 * 416 * file - file upload input. Displayed as file upload HTML input. 417 * Parameters: 418 * - value - not applicable here. 419 * - values - not applicable here. 420 * - checked - not applicable here. 421 * - collapsed - not applicable here. 422 * - html - not applicable here. 423 * - checker_func 424 * File name is passed for checking. 425 * Can be used here: Avail, Length, Preg 426 * Make no sense to use it here: Email, Date, DateTime, Captcha 427 * - db_pass 428 * File can't be stored in the database, so this field isn't applicable here. 429 * 430 * files - files upload input. Displayed as complex uploading HTML control. 431 * This control is too complex to describe it using default set of database fields, you need to use custom class to display this control. 432 * 433 * button - button control. Displayes as HTML button element. 434 * Parameters: 435 * - value - translatable button caption. 436 * - values - not applicable here. 437 * - checked - not applicable here. 438 * - collapsed - not applicable here. 439 * - html - not applicable here. 440 * - checker_func - not applicable here. 441 * - db_pass - not applicable here. 442 * 443 * image - form image button. It is displayed as HTML form image input element. 444 * Parameters: 445 * - value - not applicable here. 446 * - values - not applicable here. 447 * - checked - not applicable here. 448 * - collapsed - not applicable here. 449 * - html - not applicable here. 450 * - attrs - the following mandatory attribute must be specified here: 451 * - src - image URL. 452 * - checker_func - not applicable here. 453 * - db_pass - not applicable here. 454 * 455 * reset - form reset button. Displayed as HTML form reset input button. By clicking on this button the form is reset to its default state. 456 * Parameters: 457 * - value - translatable button caption. 458 * - values - not applicable here. 459 * - checked - not applicable here. 460 * - collapsed - not applicable here. 461 * - html - not applicable here. 462 * - checker_func - not applicable here. 463 * - db_pass - not applicable here. 464 * 465 * submit - form submit button. Displayed as HTML form submit input button. This button have the primary button style to distinguish it from other buttons. By clicking on this button the form is submitted. 466 * Parameters: 467 * - value - translatable button caption. 468 * - values - not applicable here. 469 * - checked - not applicable here. 470 * - collapsed - not applicable here. 471 * - html - not applicable here. 472 * - checker_func - not applicable here. 473 * - db_pass - not applicable here. 474 * 475 * value - just displaying value without any control. 476 * Parameters: 477 * - value - the value to display. 478 * - values - not applicable here. 479 * - checked - not applicable here. 480 * - collapsed - not applicable here. 481 * - html - not applicable here. 482 * - checker_func - not applicable here. 483 * - db_pass - not applicable here. 484 * 485 * block_header - start group of fields. Displayed as form fields divider with caption - then it can be collapsible or without caption - then it is just divider without any functionality. 486 * Parameters: 487 * - value - not applicable here. 488 * - values - not applicable here. 489 * - checked - not applicable here. 490 * - collapsed - display group of field collapsed by default, 1 - the group is collapsed, 0 - expanded (default value). 491 * - html - not applicable here. 492 * - checker_func - not applicable here. 493 * - db_pass - not applicable here. 494 * 495 * custom - custom control. You need custom class to display this control, so the exact used values are determined by particular realisation. 496 * 497 * input_set - set of other form controls. 498 * Parameters: 499 * - value - not applicable here. 500 * - values - comma separated list of field names (by name field) of fields to display here. 501 * - checked - not applicable here. 502 * - collapsed - not applicable here. 503 * - html - not applicable here. 504 * - checker_func - not applicable here. 505 * - db_pass - not applicable here. 506 * 507 * 508 * @section form_using_own_class Using own class for custom behavior 509 * 510 * It is possible to provide own class for displaying and processing the form. 511 * To do this you need to point it in override_class_name and override_class_file fields in sys_objects_form table. 512 * Your custom class must be inherited from BxTemplFormView class or its descendants. 513 * 514 * 515 * @section form_display_custom_control Displaying custom field control 516 * 517 * It is possible to leave form field with default caption and override only the form field control. 518 * To override some field you need to define the following function: 519 * @code 520 * protected function genCustomInput[field name] ($aInput). 521 * @endcode 522 * Where [field name] is form field name. 523 * For example: 524 * 525 * @code 526 * protected function genCustomInputCustom ($aInput) { 527 * return 528 * 'r: <input type="text" size="2" value="'.(isset($aInput['value'][0]) ? $aInput['value'][0] : '').'" name="'.$aInput['name'].'[]" />' . 529 * 'g: <input type="text" size="2" value="'.(isset($aInput['value'][1]) ? $aInput['value'][1] : '').'" name="'.$aInput['name'].'[]" />' . 530 * 'b: <input type="text" size="2" value="'.(isset($aInput['value'][2]) ? $aInput['value'][2] : '').'" name="'.$aInput['name'].'[]" />'; 531 * } 532 * @endcode 533 * 534 * 535 * @section form_display_custom_row Displaying custom field row 536 * 537 * Form row consists of caption and control, by default it is displayed with default design and functionality. 538 * If you need to display some field with custom header and control you need to declare the following function: 539 * @code 540 * protected function genCustomRow[field name] ($aInput). 541 * @endcode 542 * Where [field name] is form field name. 543 * 544 * 545 * @section example Example of usage 546 * 547 * Printing the form for adding new record to the database: 548 * 549 * @code 550 * bx_import('BxDolForm'); 551 * $oForm = BxDolForm::getObjectInstance('sample_form_objects', 'sample_form_objects_add'); // get form instance for specified form object and display 552 * if (!$oForm) 553 * die('"sample_form_objects_add" form object or "sample_form_objects_add" display is not defined'); 554 * $oForm->initChecker(); // init form checker witout any data - adding new record 555 * if ($oForm->isSubmittedAndValid()) 556 * echo 'inserted id: ' . $oForm->insert (); // add new record to the database 557 * echo $oForm->getCode(); // display form 558 * @endcode 559 * 560 * Printing the form for editing existing record in the database: 561 * 562 * @code 563 * // $iEditId - ID of edited row, for example from _GET parameter 564 * $oDb = BxDolDb::getInstance(); 565 * $sQuery = $oDb->prepare("SELECT * FROM `sample_input_types` WHERE id = ?", $iEditId); 566 * $aRecord = $oDb->getRow(); 567 * if (!$aRecord) 568 * die("$iEditId record wasn't found."); 569 * 570 * bx_import('BxDolForm'); 571 * $oForm = BxDolForm::getObjectInstance('sample_form_objects', 'sample_form_objects_edit'); // get form instance for specified form object and display 572 * if (!$oForm) 573 * die('"sample_form_objects_edit" form object or "sample_form_objects_edit" display is not defined'); 574 * $oForm->initChecker($aRecord); // init form checker with edited data 575 * if ($oForm->isSubmittedAndValid()) 576 * echo 'updated: ' . $oForm->update ($iEditId); // update database 577 * echo $oForm->getCode(); // display form 578 * @endcode 579 * 580 * Example of custom form class and custom checking helper class: 581 * 582 * @code 583 * bx_import('BxTemplFormView'); 584 * 585 * class BxSampleForm extends BxTemplFormView { 586 * 587 * public function __construct ($aInfo, $oTemplate = false) { 588 * parent::__construct ($aInfo, $oTemplate); 589 * } 590 * 591 * 592 * // display input with 'custom' name 593 * protected function genCustomInputCustom ($aInput) { 594 * return 595 * 'r: <input type="text" size="2" value="'.(isset($aInput['value'][0]) ? $aInput['value'][0] : '').'" name="'.$aInput['name'].'[]" />' . 596 * 'g: <input type="text" size="2" value="'.(isset($aInput['value'][1]) ? $aInput['value'][1] : '').'" name="'.$aInput['name'].'[]" />' . 597 * 'b: <input type="text" size="2" value="'.(isset($aInput['value'][2]) ? $aInput['value'][2] : '').'" name="'.$aInput['name'].'[]" />'; 598 * } 599 * 600 * } 601 * 602 * class BxSampleFormCheckerHelper extends BxDolFormCheckerHelper { 603 * 604 * var $_sDiv = ','; 605 * 606 * // prepare RBG values to save to the DB 607 * function passRgb ($s) { 608 * if (!is_array($s)) 609 * return false; 610 * 611 * $sRet = ''; 612 * foreach ($s as $k => $v) 613 * $sRet .= (int)trim($v) . $this->_sDiv; 614 * 615 * return trim($sRet, $this->_sDiv); 616 * } 617 * 618 * // prepare RGB values to output to the screen 619 * function displayRgb ($s) { 620 * return explode($this->_sDiv, $s); 621 * } 622 * } 623 * @endcode 624 * 625 * The recommended way is to define forms in database, if it is impossible for some reasons you can init form object from array, there is an example: 29 626 * 30 627 * @code … … 88 685 * @endcode 89 686 * 90 * Example of using:687 * Using of above array: 91 688 * 92 689 * @code … … 110 707 * 111 708 * @endcode 709 * 112 710 */ 113 711 class BxDolForm extends BxDol { … … 400 998 401 999 foreach ($aInputs as $k => $a) { 402 if (empty($a['name']) )1000 if (empty($a['name']) || 'submit' == $a['type'] || 'reset' == $a['type'] || 'button' == $a['type']) 403 1001 continue; 1002 404 1003 $a['name'] = str_replace('[]', '', $a['name']); 405 1004 $val = BxDolForm::getSubmittedValue($a['name'], $this->_sFormMethod, $this->_aSpecificValues); -
trunk/inc/js/jquery.webForms.js
r15793 r15798 92 92 var iSliderWidth = eInput.innerWidth() - 100; 93 93 $(this).css('width', iSliderWidth + 'px').css('top', (eInput.innerHeight() - $(this).outerHeight())/2 + 1 + 'px'); 94 eInput.css('padding-right', (iSliderWidth + parse Int($(this).css('margin-right')) + 10) + 'px');94 eInput.css('padding-right', (iSliderWidth + parseFloat($(this).css('margin-right')) + 10) + 'px'); 95 95 }; 96 96 … … 106 106 var $slider = $('<div class="bx-def-margin-right"></div>').insertAfter(cur); 107 107 108 var iMin = cur.attr("min") ? parse Int(cur.attr("min"), 10) : 0;109 var iMax = cur.attr("max") ? parse Int(cur.attr("max"), 10) : 100;108 var iMin = cur.attr("min") ? parseFloat(cur.attr("min"), 10) : 0; 109 var iMax = cur.attr("max") ? parseFloat(cur.attr("max"), 10) : 100; 110 110 var sRangeDv = cur.attr("range-divider") ? cur.attr("range-divider") : '-'; 111 111 … … 115 115 116 116 if (typeof(values[0]) != 'undefined' && values[0].length) 117 values[0] = parse Int(values[0]);117 values[0] = parseFloat(values[0]); 118 118 else 119 119 values[0] = iMin; 120 120 121 121 if (typeof(values[1]) != 'undefined' && values[1].length) 122 values[1] = parse Int(values[1]);122 values[1] = parseFloat(values[1]); 123 123 else 124 124 values[1] = iMax; … … 136 136 min: iMin, 137 137 max: iMax, 138 step: parse Int(cur.attr("step")) |1,138 step: parseFloat(cur.attr("step")) ? parseFloat(cur.attr("step")) : 1, 139 139 values: funcGetValues(cur), 140 140 change: onChange, … … 163 163 $slider.css('width', ($slider.parent().innerWidth() - cur.outerWidth() - 50) + 'px'); 164 164 165 var iMin = cur.attr("min") ? parse Int(cur.attr("min"), 10) : 0;166 var iMax = cur.attr("max") ? parse Int(cur.attr("max"), 10) : 100;165 var iMin = cur.attr("min") ? parseFloat(cur.attr("min"), 10) : 0; 166 var iMax = cur.attr("max") ? parseFloat(cur.attr("max"), 10) : 100; 167 167 168 168 var onChange = function(e, ui) { … … 173 173 min: iMin, 174 174 max: iMax, 175 step: parse Int(cur.attr("step")) |1,175 step: parseFloat(cur.attr("step")) ? parseFloat(cur.attr("step")) : 1, 176 176 value: cur.val(), 177 177 change: onChange,
Note: See TracChangeset
for help on using the changeset viewer.