| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
class BasesfFormBuilder |
|---|
| 25 |
{ |
|---|
| 26 |
|
|---|
| 27 |
* Module Name |
|---|
| 28 |
* |
|---|
| 29 |
* Name of the module this form builder instance is in. Auto loaded but can be manually set after instantiated. |
|---|
| 30 |
* |
|---|
| 31 |
* <code> |
|---|
| 32 |
* $sfFormBuilder->setModuleName('module_name'); |
|---|
| 33 |
* $sfFormBuilder->getModuleName(); |
|---|
| 34 |
* </code> |
|---|
| 35 |
* |
|---|
| 36 |
* @var string |
|---|
| 37 |
* @access public |
|---|
| 38 |
*/ |
|---|
| 39 |
public $moduleName = ''; |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
* Action Name |
|---|
| 43 |
* |
|---|
| 44 |
* Name of the action this form builder instance is in. Auto loaded but can be manually set after instantiated. |
|---|
| 45 |
* |
|---|
| 46 |
* <code> |
|---|
| 47 |
* $sfFormBuilder->setActionName('action_name'); |
|---|
| 48 |
* $sfFormBuilder->getActionName(); |
|---|
| 49 |
* </code> |
|---|
| 50 |
* |
|---|
| 51 |
* @var string |
|---|
| 52 |
* @access public |
|---|
| 53 |
*/ |
|---|
| 54 |
public $actionName = ''; |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
* Form Builder Id |
|---|
| 58 |
* |
|---|
| 59 |
* Unique id for this form |
|---|
| 60 |
* |
|---|
| 61 |
* <code> |
|---|
| 62 |
* $sfFormBuilder->setId('unique_form_builder_id'); |
|---|
| 63 |
* $sfFormBuilder->getId(); |
|---|
| 64 |
* </code> |
|---|
| 65 |
* |
|---|
| 66 |
* @var string |
|---|
| 67 |
* @access public |
|---|
| 68 |
*/ |
|---|
| 69 |
public $id = ''; |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
* Model Name |
|---|
| 73 |
* |
|---|
| 74 |
* Main model name the form is based off of. Not required. |
|---|
| 75 |
* |
|---|
| 76 |
* <code> |
|---|
| 77 |
* $sfFormBuilder->setModelName('Model'); |
|---|
| 78 |
* $sfFormBuilder->getModelName(); |
|---|
| 79 |
* </code> |
|---|
| 80 |
* |
|---|
| 81 |
* @var string |
|---|
| 82 |
* @access public |
|---|
| 83 |
*/ |
|---|
| 84 |
public $modelName = ''; |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
* Model Peer Name |
|---|
| 89 |
* |
|---|
| 90 |
* Automatically set from the model name passed to the constructor but can be manually set like the others |
|---|
| 91 |
* |
|---|
| 92 |
* <code> |
|---|
| 93 |
* $sfFormBuilder->setModelPeerName('ModelPeer'); |
|---|
| 94 |
* $sfFormBuilder->getModelPeerName(); |
|---|
| 95 |
* </code> |
|---|
| 96 |
* |
|---|
| 97 |
* @var string |
|---|
| 98 |
* @access public |
|---|
| 99 |
*/ |
|---|
| 100 |
public $modelPeerName = ''; |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
* Form Builder Name |
|---|
| 104 |
* |
|---|
| 105 |
* Name of the actual <form> tag. Automatically generated when setId() but can be manually set with setName() |
|---|
| 106 |
* |
|---|
| 107 |
* <code> |
|---|
| 108 |
* $sfFormBuilder->setName('name_of_form'); |
|---|
| 109 |
* $sfFormBuilder->getName(); |
|---|
| 110 |
* </code> |
|---|
| 111 |
* |
|---|
| 112 |
* @var string |
|---|
| 113 |
* @access public |
|---|
| 114 |
*/ |
|---|
| 115 |
public $name = ''; |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
* Form Builder Title(uses sfContentGetter plugin) |
|---|
| 119 |
* |
|---|
| 120 |
* Title/header of the form builder. Set by setTitle() and can accept html/string, a partial name(_partial_name), or a component name(__component_name) |
|---|
| 121 |
* |
|---|
| 122 |
* <code> |
|---|
| 123 |
* $formBuilder->setTitle('Title'); // will render as a simple string "Title" |
|---|
| 124 |
* $formBuilder->setTitle('_title'); // will render the partial template _title.php |
|---|
| 125 |
* $formBuilder->setTitle('__title'); // will render the component __title in components.class.php executeTitle() and _title.php for the component template |
|---|
| 126 |
* |
|---|
| 127 |
* $formBuilder->getTitle(); // returns the content string to be parsed |
|---|
| 128 |
* $formBuilder->getRenderedTitle(); // parses and returns the content evaluated string |
|---|
| 129 |
* </code> |
|---|
| 130 |
* |
|---|
| 131 |
* @var string |
|---|
| 132 |
* @access public |
|---|
| 133 |
*/ |
|---|
| 134 |
public $title = null; |
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
* titleRowContentGetter |
|---|
| 138 |
* |
|---|
| 139 |
* @var mixed |
|---|
| 140 |
* @access public |
|---|
| 141 |
*/ |
|---|
| 142 |
public $titleRowContentGetter = null; |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
* footerRowContentGetter |
|---|
| 146 |
* |
|---|
| 147 |
* @var mixed |
|---|
| 148 |
* @access public |
|---|
| 149 |
*/ |
|---|
| 150 |
public $footerRowContentGetter = null; |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
* Show Title (true/false) |
|---|
| 154 |
* |
|---|
| 155 |
* <code> |
|---|
| 156 |
* $sfFormBuilder->setShowTitle(false); |
|---|
| 157 |
* $sfFormBuilder->getShowTitle(); |
|---|
| 158 |
* </code> |
|---|
| 159 |
* |
|---|
| 160 |
* @var mixed |
|---|
| 161 |
* @access public |
|---|
| 162 |
*/ |
|---|
| 163 |
public $showTitle = true; |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
* Show Footer (true/false) |
|---|
| 167 |
* |
|---|
| 168 |
* <code> |
|---|
| 169 |
* $sfFormBuilder->setShowFooter(false); |
|---|
| 170 |
* $sfFormBuilder->getShowFooter(); |
|---|
| 171 |
* </code> |
|---|
| 172 |
* |
|---|
| 173 |
* @var mixed |
|---|
| 174 |
* @access public |
|---|
| 175 |
*/ |
|---|
| 176 |
public $showFooter = true; |
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
* Show Submit Buttons (true/false) |
|---|
| 180 |
* |
|---|
| 181 |
* <code> |
|---|
| 182 |
* $sfFormBuilder->setShowSubmitButton(false); |
|---|
| 183 |
* $sfFormBuilder->getShowSubmitButtons(); |
|---|
| 184 |
* </code> |
|---|
| 185 |
* |
|---|
| 186 |
* @var mixed |
|---|
| 187 |
* @access public |
|---|
| 188 |
*/ |
|---|
| 189 |
public $showSubmitButtons = true; |
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
* Form Builder Action (url/route) |
|---|
| 193 |
* |
|---|
| 194 |
* Url or route for the form builder action to submit to |
|---|
| 195 |
* |
|---|
| 196 |
* <code> |
|---|
| 197 |
* $sfFormBuilder->setAction('module/action'); |
|---|
| 198 |
* $sfFormBuilder->setAction('@route'); |
|---|
| 199 |
* $sfFormBuilder->setAction('http://www.domain.com'); |
|---|
| 200 |
* $sfFormBuilder->getAction(); |
|---|
| 201 |
* </code> |
|---|
| 202 |
* |
|---|
| 203 |
* @var string |
|---|
| 204 |
* @access public |
|---|
| 205 |
*/ |
|---|
| 206 |
public $action = ''; |
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
* Form Builder Action Method |
|---|
| 210 |
* |
|---|
| 211 |
* The method the form should be submitted with. (GET or POST) |
|---|
| 212 |
* |
|---|
| 213 |
* <code> |
|---|
| 214 |
* $sfFormBuilder->setActionMethod('POST'); |
|---|
| 215 |
* $sfFormBuilder->setAction('@route', 'POST'); // 2nd argument of setAction can optionally be the method to use for the action |
|---|
| 216 |
* $sfFormBuilder->getActionMethod(); |
|---|
| 217 |
* </code> |
|---|
| 218 |
* |
|---|
| 219 |
* @var string |
|---|
| 220 |
* @access public |
|---|
| 221 |
*/ |
|---|
| 222 |
public $actionMethod = 'POST'; |
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
* Form Builder Extra |
|---|
| 226 |
* |
|---|
| 227 |
* Any extra html parameters for the <form> tag |
|---|
| 228 |
* |
|---|
| 229 |
* <code> |
|---|
| 230 |
* // Will alert 'test' when the form submits |
|---|
| 231 |
* // Use this to set an extra parameters on the <form> tag |
|---|
| 232 |
* $sfFormBuilder->setExtra('onSubmit="javscript: alert(\'test\');"'); |
|---|
| 233 |
* $sfFormBuilder->getExtra(); |
|---|
| 234 |
* </code> |
|---|
| 235 |
* |
|---|
| 236 |
* @var string |
|---|
| 237 |
* @access public |
|---|
| 238 |
*/ |
|---|
| 239 |
public $extra = ''; |
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
* Form Builder Hidden Fields |
|---|
| 243 |
* |
|---|
| 244 |
* Array of the hidden fields to be included in the form |
|---|
| 245 |
* |
|---|
| 246 |
* <code> |
|---|
| 247 |
* $sfFormBuilder->addHiddenField('name', 'value'); |
|---|
| 248 |
* $sfFormBuilder->getHiddenFields(); |
|---|
| 249 |
* </code> |
|---|
| 250 |
* |
|---|
| 251 |
* @var array |
|---|
| 252 |
* @access public |
|---|
| 253 |
*/ |
|---|
| 254 |
public $hiddenFields = array(); |
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
* Form Builder Submit Buttons |
|---|
| 258 |
* |
|---|
| 259 |
* Array of the submit buttons to be included at the bottom of the form |
|---|
| 260 |
* |
|---|
| 261 |
* <code> |
|---|
| 262 |
* $sfFormBuilder->addSubmitButton('name', array()); // 2nd argument accepts default arguments for a form submit button. Can either be an array or string. http://www.symfony-project.com/api/symfony/helper/FormHelper.html |
|---|
| 263 |
* $sfFormBuilder->getSubmitButtons(); |
|---|
| 264 |
* </code> |
|---|
| 265 |
* |
|---|
| 266 |
* @var array |
|---|
| 267 |
* @access public |
|---|
| 268 |
*/ |
|---|
| 269 |
public $submitButtons = array(); |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
* Form Builder Elements |
|---|
| 273 |
* |
|---|
| 274 |
* Array of all the elements of the form builder |
|---|
| 275 |
* |
|---|
| 276 |
* <code> |
|---|
| 277 |
* $sfFormBuilder->addCheckboxTag('Checkbox', 'checkbox_1', 1, true, array()); |
|---|
| 278 |
* // If a module is not specified it inherits the module you are in |
|---|
| 279 |
* $sfFormBuilder->addContentGetter('Content Getter', '_content_getter', array()); // partial _content_getter_1.php |
|---|
| 280 |
* $sfFormBuilder->addContentGetter('Content Getter', '__content_getter', array()); // partial _content_getter_1.php |
|---|
| 281 |
* $sfFormBuilder->addContentGetter('Content Getter', '___content_getter', array()); // partial _content_getter_1.php |
|---|
| 282 |
* $sfFormBuilder->addContentGetter('Content Getter', 'module_name/{any of the content_getter strings used above}', array()); // partial _content_getter_1.php |
|---|
| 283 |
* $sfFormBuilder->addFiller(); // simply adds a blank form element to take a space in the form |
|---|
| 284 |
* </code> |
|---|
| 285 |
* |
|---|
| 286 |
* http://www.symfony-project.com/api/symfony/helper/FormHelper.html |
|---|
| 287 |
* Method exists for each one of the default symfony form helpers. Same arguments except the first argument of our function is the label of the element. |
|---|
| 288 |
* |
|---|
| 289 |
* http://www.symfony-project.com/api/symfony/helper/ObjectHelper.html |
|---|
| 290 |
* Object tags can be added with: |
|---|
| 291 |
* <code> |
|---|
| 292 |
* $sfFormBuilder->addObjectTag('Label', 'object_helper_function_name', 'Object', 'getMethod', array()); |
|---|
| 293 |
* |
|---|
| 294 |
* $sfFormBuilder->getElements(); |
|---|
| 295 |
* </code> |
|---|
| 296 |
* |
|---|
| 297 |
* @var array |
|---|
| 298 |
* @access public |
|---|
| 299 |
*/ |
|---|
| 300 |
public $elements = array(); |
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
* Element Groups |
|---|
| 304 |
* |
|---|
| 305 |
* Array of the element groups for this form builder |
|---|
| 306 |
* |
|---|
| 307 |
* <code> |
|---|
| 308 |
* // 2nd argument is an array/string of options. sfContentGetter plugin for parsing the title to allow content to be result of an action, partial, or component. |
|---|
| 309 |
* // _partial |
|---|
| 310 |
* // __component |
|---|
| 311 |
* // ___action |
|---|
| 312 |
* // module_name/any_of_the_above |
|---|
| 313 |
* $sfFormBuilder->startElementGroup('unique_group_name', 'title=content_getter_string'); |
|---|
| 314 |
* $sfFormBuilder->getElementGroups(); |
|---|
| 315 |
* </code> |
|---|
| 316 |
* |
|---|
| 317 |
* @var array |
|---|
| 318 |
* @access public |
|---|
| 319 |
*/ |
|---|
| 320 |
public $elementGroups = array(); |
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 |
* Current Element Group |
|---|
| 324 |
* |
|---|
| 325 |
* Var to hold the name of the current element group |
|---|
| 326 |
* |
|---|
| 327 |
* <code> |
|---|
| 328 |
* $this->setCurrentElementGroup('unique_group_name'); |
|---|
| 329 |
* $this->getCurrentElementGroup();; |
|---|
| 330 |
* </code> |
|---|
| 331 |
* |
|---|
| 332 |
* @var mixed |
|---|
| 333 |
* @access public |
|---|
| 334 |
*/ |
|---|
| 335 |
protected $currentElementGroup; |
|---|
| 336 |
|
|---|
| 337 |
|
|---|
| 338 |
* Show Element Groups |
|---|
| 339 |
* |
|---|
| 340 |
* Flag for whether or not to show the element groups |
|---|
| 341 |
* |
|---|
| 342 |
* <code> |
|---|
| 343 |
* $sfFormBuilder->setShowElementGroups(false); |
|---|
| 344 |
* $sfFormBuilder->getShowElementGroups(); |
|---|
| 345 |
* </code> |
|---|
| 346 |
* |
|---|
| 347 |
* @var mixed |
|---|
| 348 |
* @access public |
|---|
| 349 |
*/ |
|---|
| 350 |
public $showElementGroups = true; |
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
* Form Builder Collapsible |
|---|
| 354 |
* |
|---|
| 355 |
* Bool value for whether or not the form is collapsible |
|---|
| 356 |
* |
|---|
| 357 |
* <code> |
|---|
| 358 |
* $sfFormBuilder->setCollapsible(false); |
|---|
| 359 |
* $sfFormBuilder->getCollapsible(); |
|---|
| 360 |
* </code> |
|---|
| 361 |
* |
|---|
| 362 |
* @var bool |
|---|
| 363 |
* @access public |
|---|
| 364 |
*/ |
|---|
| 365 |
public $collapsible = true; |
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
* Groups Collapsible |
|---|
| 369 |
* |
|---|
| 370 |
* @var mixed |
|---|
| 371 |
* @access public |
|---|
| 372 |
*/ |
|---|
| 373 |
public $groupsCollapsible = true; |
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
* Fill In Form |
|---|
| 377 |
* |
|---|
| 378 |
* This is an alternate method to using the sfFillInFormFilter |
|---|
| 379 |
* |
|---|
| 380 |
* <code> |
|---|
| 381 |
* $sfFormBuilder->setFillInForm(false); |
|---|
| 382 |
* $sfFormBuilder->getFillInForm(); |
|---|
| 383 |
* </code> |
|---|
| 384 |
* |
|---|
| 385 |
* @var mixed |
|---|
| 386 |
* @access public |
|---|
| 387 |
*/ |
|---|
| 388 |
public $fillInForm = true; |
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
* Rounder Corners |
|---|
| 392 |
* |
|---|
| 393 |
* Bool value for whether or not to use sfNiftyCorners plugin to round the corns of our form tables |
|---|
| 394 |
* |
|---|
| 395 |
* <code> |
|---|
| 396 |
* $sfFormBuilder->setRoundCorners(false); |
|---|
| 397 |
* $sfFormBuilder->getRoundCorners(); |
|---|
| 398 |
* </code> |
|---|
| 399 |
* |
|---|
| 400 |
* @var mixed |
|---|
| 401 |
* @access public |
|---|
| 402 |
*/ |
|---|
| 403 |
public $roundCorners = true; |
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
* Label Style |
|---|
| 407 |
* |
|---|
| 408 |
* over, left |
|---|
| 409 |
* |
|---|
| 410 |
* <code> |
|---|
| 411 |
* $sfFormBuilder->setLabelStyle('left'); |
|---|
| 412 |
* $sfFormBuilder->setLabelStyle('over'); |
|---|
| 413 |
* $sfFormBuilder->setStyle('over', 1); |
|---|
| 414 |
* $sfFormBuilder->getLabelStyle(); |
|---|
| 415 |
* // over - the label is over the form element |
|---|
| 416 |
* // left - the label is to the left of the form element |
|---|
| 417 |
* </code> |
|---|
| 418 |
* |
|---|
| 419 |
* @var string |
|---|
| 420 |
* @access public |
|---|
| 421 |
*/ |
|---|
| 422 |
public $labelStyle = 'over'; |
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
* Label Width |
|---|
| 426 |
* |
|---|
| 427 |
* Manually override the css label width for this form instance |
|---|
| 428 |
* |
|---|
| 429 |
* <code> |
|---|
| 430 |
* $sfFormBuilder->setLabelWidth('300px'); |
|---|
| 431 |
* $sfFormBuilder->getLabelWidth(); |
|---|
| 432 |
* </code> |
|---|
| 433 |
* |
|---|
| 434 |
* @var mixed |
|---|
| 435 |
* @access public |
|---|
| 436 |
*/ |
|---|
| 437 |
public $labelWidth; |
|---|
| 438 |
|
|---|
| 439 |
|
|---|
| 440 |
* Number of Element Columns |
|---|
| 441 |
* |
|---|
| 442 |
* <code> |
|---|
| 443 |
* $sfFormBuilder->setNumberOfElementColumns(1); // max number of 3 columns |
|---|
| 444 |
* $sfFormBuilder->getNumberOfElementColumns(); |
|---|
| 445 |
* $sfFormBuilder->setStyle('over', 1); |
|---|
| 446 |
* </code> |
|---|
| 447 |
* |
|---|
| 448 |
* @var string |
|---|
| 449 |
* @access public |
|---|
| 450 |
*/ |
|---|
| 451 |
public $numberOfElementColumns = 2; |
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
* Filler Count |
|---|
| 455 |
* |
|---|
| 456 |
* Var to keep count of the number of fillers used |
|---|
| 457 |
* |
|---|
| 458 |
* <code> |
|---|
| 459 |
* $sfFormBuilder->setFillerCount((int) 1); |
|---|
| 460 |
* $sfFormBuilder->getFillerCount(); |
|---|
| 461 |
* $sfFormBuilder->incrementFillerCount(); // increment filler count by 1 |
|---|
| 462 |
* </code> |
|---|
| 463 |
* |
|---|
| 464 |
* @var float |
|---|
| 465 |
* @access public |
|---|
| 466 |
*/ |
|---|
| 467 |
protected $fillerCount = 0; |
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
* Html |
|---|
| 471 |
* |
|---|
| 472 |
* Var to hold final html output of the form builder |
|---|
| 473 |
* |
|---|
| 474 |
* <code> |
|---|
| 475 |
* $sfFormBuilder->setHtml('html content'); |
|---|
| 476 |
* $sfFormBuilder->getHtml(); |
|---|
| 477 |
* </code> |
|---|
| 478 |
* |
|---|
| 479 |
* @var string |
|---|
| 480 |
* @access public |
|---|
| 481 |
*/ |
|---|
| 482 |
public $html = ''; |
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
* __construct |
|---|
| 486 |
* |
|---|
| 487 |
* Set up all the information needed for the form builder from the model name passed |
|---|
| 488 |
* |
|---|
| 489 |
* <code> |
|---|
| 490 |
* $sfFormBuilder = new sfFormBuilder('Model'); |
|---|
| 491 |
* echo $sfFormBuilder->output(); |
|---|
| 492 |
* </code> |
|---|
| 493 |
* |
|---|
| 494 |
* @param string $modelName |
|---|
| 495 |
* @access public |
|---|
| 496 |
* @return void |
|---|
| 497 |
*/ |
|---|
| 498 |
public function __construct($modelName = null) |
|---|
| 499 |
{ |
|---|
| 500 |
$this->loadDefaultsFromConfig(); |
|---|
| 501 |
|
|---|
| 502 |
$this->setModuleName($this->getRequest()->getParameter('module')); |
|---|
| 503 |
$this->setActionName($this->getRequest()->getParameter('action')); |
|---|
| 504 |
$this->setId(sfInflector::underscore($modelName).'_form_builder'); |
|---|
| 505 |
|
|---|
| 506 |
if( $modelName ) |
|---|
| 507 |
{ |
|---|
| 508 |
$this->setModelName($modelName); |
|---|
| 509 |
$this->setModelPeerName($modelName.'Peer'); |
|---|
| 510 |
} |
|---|
| 511 |
|
|---|
| 512 |
$this->setAction($this->getRequest()->getPathInfo()); |
|---|
| 513 |
} |
|---|
| 514 |
|
|---|
| 515 |
|
|---|
| 516 |
* Load Defaults From Configuration |
|---|
| 517 |
* |
|---|
| 518 |
* @access protected |
|---|
| 519 |
* @return void |
|---|
| 520 |
*/ |
|---|
| 521 |
protected function loadDefaultsFromConfig() |
|---|
| 522 |
{ |
|---|
| 523 |
foreach($this AS $key => $value) |
|---|
| 524 |
{ |
|---|
| 525 |
$name = 'app_form_builder_'.sfInflector::underscore($key); |
|---|
| 526 |
|
|---|
| 527 |
$newValue = sfConfig::get($name); |
|---|
| 528 |
|
|---|
| 529 |
if( isset($newValue) && $newValue != $value ) |
|---|
| 530 |
{ |
|---|
| 531 |
$funcName = 'set'.ucfirst($key); |
|---|
| 532 |
$this->$funcName($newValue);; |
|---|
| 533 |
} |
|---|
| 534 |
} |
|---|
| 535 |
} |
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
* Set Module Action |
|---|
| 539 |
* |
|---|
| 540 |
* @param mixed $module |
|---|
| 541 |
* @param mixed $action |
|---|
| 542 |
* @access public |
|---|
| 543 |
* @return void |
|---|
| 544 |
*/ |
|---|
| 545 |
public function setModuleAction($module, $action) |
|---|
| 546 |
{ |
|---|
| 547 |
$this->setModuleName($module); |
|---|
| 548 |
$this->setActionName($action); |
|---|
| 549 |
} |
|---|
| 550 |
|
|---|
| 551 |
|
|---|
| 552 |
* Set Action |
|---|
| 553 |
* |
|---|
| 554 |
* @param mixed $action |
|---|
| 555 |
* @param mixed $method |
|---|
| 556 |
* @access public |
|---|
| 557 |
* @return void |
|---|
| 558 |
*/ |
|---|
| 559 |
public function setAction($action, $method = null) |
|---|
| 560 |
{ |
|---|
| 561 |
$this->action = $action; |
|---|
| 562 |
|
|---|
| 563 |
if( $method ) |
|---|
| 564 |
{ |
|---|
| 565 |
$this->actionmethod = $method; |
|---|
| 566 |
} |
|---|
| 567 |
} |
|---|
| 568 |
|
|---|
| 569 |
|
|---|
| 570 |
* Set Style |
|---|
| 571 |
* |
|---|
| 572 |
* Set the overall style for this form builder instance. Controlled via css. |
|---|
| 573 |
* |
|---|
| 574 |
* <code> |
|---|
| 575 |
* $sfFormBuilder->setStyle('left', 1'); // normal form with 1 column of elements, with the label to the left of the elements, listed vertically |
|---|
| 576 |
* // Max of 3 columns, and the style can be 'left' or 'over' |
|---|
| 577 |
* </code> |
|---|
| 578 |
* |
|---|
| 579 |
* @param mixed $labelStyle |
|---|
| 580 |
* @param mixed $numberOfElementColumns |
|---|
| 581 |
* @access public |
|---|
| 582 |
* @return void |
|---|
| 583 |
*/ |
|---|
| 584 |
public function setStyle($labelStyle, $numberOfElementColumns = null) |
|---|
| 585 |
{ |
|---|
| 586 |
$this->setLabelStyle($labelStyle); |
|---|
| 587 |
|
|---|
| 588 |
if( $numberOfElementColumns ) |
|---|
| 589 |
{ |
|---|
| 590 |
$this->setNumberOfElementColumns($numberOfElementColumns); |
|---|
| 591 |
} |
|---|
| 592 |
} |
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
* Set Number of Element Columns |
|---|
| 596 |
* |
|---|
| 597 |
* Set the number of element columns to display the form elements in |
|---|
| 598 |
* |
|---|
| 599 |
* <code> |
|---|
| 600 |
* $sfFormBuilder->setNumberOfElementColumns(3); // maximum of 3 columns |
|---|
| 601 |
* </code> |
|---|
| 602 |
* |
|---|
| 603 |
* @param mixed $num |
|---|
| 604 |
* @access public |
|---|
| 605 |
* @return void |
|---|
| 606 |
*/ |
|---|
| 607 |
public function setNumberOfElementColumns($num) |
|---|
| 608 |
{ |
|---|
| 609 |
if( $num > 3 ) |
|---|
| 610 |
{ |
|---|
| 611 |
throw new Exception('sfFormBuilder does not support any more than 3 element columns'); |
|---|
| 612 |
} |
|---|
| 613 |
|
|---|
| 614 |
$this->numberOfElementColumns = $num; |
|---|
| 615 |
} |
|---|
| 616 |
|
|---|
| 617 |
|
|---|
| 618 |
|
|---|
| 619 |
|
|---|
| 620 |
* Get Form Builder Collapsed Status |
|---|
| 621 |
* |
|---|
| 622 |
* Retrieve the current saved collapsed status value |
|---|
| 623 |
* |
|---|
| 624 |
* @access protected |
|---|
| 625 |
* @return bool $status |
|---|
| 626 |
*/ |
|---|
| 627 |
protected function getCollapsedStatus() |
|---|
| 628 |
{ |
|---|
| 629 |
return $this->getUser()->getAttribute($this->getId().'_collapsed_status'); |
|---|
| 630 |
} |
|---|
| 631 |
|
|---|
| 632 |
|
|---|
| 633 |
* Is Form Builder Collapsed |
|---|
| 634 |
* |
|---|
| 635 |
* Check to see if the current form is collapsed or not |
|---|
| 636 |
* |
|---|
| 637 |
* @access protected |
|---|
| 638 |
* @return bool $status |
|---|
| 639 |
*/ |
|---|
| 640 |
protected function isCollapsed() |
|---|
| 641 |
{ |
|---|
| 642 |
return $this->getCollapsedStatus(); |
|---|
| 643 |
} |
|---|
| 644 |
|
|---|
| 645 |
|
|---|
| 646 |
* Get Request |
|---|
| 647 |
* |
|---|
| 648 |
* Get the current sfRequest object instance |
|---|
| 649 |
* |
|---|
| 650 |
* @access protected |
|---|
| 651 |
* @return object $request |
|---|
| 652 |
*/ |
|---|
| 653 |
protected function getRequest() |
|---|
| 654 |
{ |
|---|
| 655 |
return sfContext::getInstance()->getRequest(); |
|---|
| 656 |
} |
|---|
| 657 |
|
|---|
| 658 |
|
|---|
| 659 |
* Get Response |
|---|
| 660 |
* |
|---|
| 661 |
* Get the current sfResponse object instance |
|---|
| 662 |
* |
|---|
| 663 |
* @access protected |
|---|
| 664 |
* @return object $response |
|---|
| 665 |
*/ |
|---|
| 666 |
protected function getResponse() |
|---|
| 667 |
{ |
|---|
| 668 |
return sfContext::getInstance()->getResponse(); |
|---|
| 669 |
} |
|---|
| 670 |
|
|---|
| 671 |
|
|---|
| 672 |
* Get User |
|---|
| 673 |
* |
|---|
| 674 |
* Get the current sfUser object instance |
|---|
| 675 |
* |
|---|
| 676 |
* @access protected |
|---|
| 677 |
* @return $object $user |
|---|
| 678 |
*/ |
|---|
| 679 |
protected function getUser() |
|---|
| 680 |
{ |
|---|
| 681 |
return sfContext::getInstance()->getUser(); |
|---|
| 682 |
} |
|---|
| 683 |
|
|---|
| 684 |
|
|---|
| 685 |
* Enable File Uploading |
|---|
| 686 |
* |
|---|
| 687 |
* Calling this function will automatically add enctype="multipart/form-data" to the <form> tag. This function is called when you add a input file tag to the form |
|---|
| 688 |
* |
|---|
| 689 |
* @access public |
|---|
| 690 |
* @return void |
|---|
| 691 |
*/ |
|---|
| 692 |
public function enableFileUploading() |
|---|
| 693 |
{ |
|---|
| 694 |
$extra = $this->getExtra(); |
|---|
| 695 |
|
|---|
| 696 |
if( !strstr($extra, 'multipart/form-data') ) |
|---|
| 697 |
{ |
|---|
| 698 |
$this->setExtra('enctype="multipart/form-data"'); |
|---|
| 699 |
} |
|---|
| 700 |
} |
|---|
| 701 |
|
|---|
| 702 |
|
|---|
| 703 |
* Disable File Uploading |
|---|
| 704 |
* |
|---|
| 705 |
* Remove the enctype="multipart/form-data" from the <form> tag and disable file uploading from this form |
|---|
| 706 |
* |
|---|
| 707 |
* @access public |
|---|
| 708 |
* @return void |
|---|
| 709 |
*/ |
|---|
| 710 |
public function disableFileUploading() |
|---|
| 711 |
{ |
|---|
| 712 |
$this->setExtra(str_replace('enctype="multipart/form-data"', '', $this->getExtra())); |
|---|
| 713 |
} |
|---|
| 714 |
|
|---|
| 715 |
|
|---|
| 716 |
* Increment Filler Count |
|---|
| 717 |
* |
|---|
| 718 |
* Keep track of how many fillers we have added because it is needed for some the name of the filler. |
|---|
| 719 |
* |
|---|
| 720 |
* @access protected |
|---|
| 721 |
* @return void |
|---|
| 722 |
*/ |
|---|
| 723 |
protected function incrementFillerCount() |
|---|
| 724 |
{ |
|---|
| 725 |
$fillerCount = $this->getFillerCount(); |
|---|
| 726 |
$fillerCount++; |
|---|
| 727 |
|
|---|
| 728 |
$this->setFillerCount($fillerCount); |
|---|
| 729 |
} |
|---|
| 730 |
|
|---|
| 731 |
|
|---|
| 732 |
* Start Element Group |
|---|
| 733 |
* |
|---|
| 734 |
* Call this before adding form elements, and it will grouped in this "element group" |
|---|
| 735 |
* |
|---|
| 736 |
* <code> |
|---|
| 737 |
* // title uses the sfContentGetter plugin for parsing an rendering the title. |
|---|
| 738 |
* $sfFormBuilder->startElementGroup('group_name', 'title=content_getter_string'); |
|---|
| 739 |
* $sfFormBuilder->getElementGroups(); |
|---|
| 740 |
* </code> |
|---|
| 741 |
* |
|---|
| 742 |
* @param mixed $name |
|---|
| 743 |
* @access public |
|---|
| 744 |
* @return void |
|---|
| 745 |
*/ |
|---|
| 746 |
public function startElementGroup($name, $options = array()) |
|---|
| 747 |
{ |
|---|
| 748 |
$options = _parse_attributes($options); |
|---|
| 749 |
|
|---|
| 750 |
$title = array_key_exists('title', $options) ? $options['title']:ucwords(sfInflector::humanize($name)); |
|---|
| 751 |
$options['title'] = $title; |
|---|
| 752 |
|
|---|
| 753 |
$this->elementGroups[$name] = $options; |
|---|
| 754 |
|
|---|
| 755 |
$this->setCurrentElementGroup($name); |
|---|
| 756 |
} |
|---|
| 757 |
|
|---|
| 758 |
|
|---|
| 759 |
* Add Form Builder Object Tag |
|---|
| 760 |
* |
|---|
| 761 |
* Add a form builder element that uses one of the object_tag helpers |
|---|
| 762 |
* |
|---|
| 763 |
* <code> |
|---|
| 764 |
* $sfFormBuilder->addObjectTag('User', 'select_tag', 'User', 'getChildId', 'related_class=User peer_method=retrieveChildren()'); |
|---|
| 765 |
* </code> |
|---|
| 766 |
* |
|---|
| 767 |
* @param string $label Label to be used for the form element |
|---|
| 768 |
* @param string $formHelper Name of the object_tag helper to be used |
|---|
| 769 |
* @param mixed $object Name of the object to instantiate or an already instaniated Model |
|---|
| 770 |
* @param string $method Method to use to call on the object to get the value and name of field |
|---|
| 771 |
* @param array $options Array or string of options accepted by the object input tag. |
|---|
| 772 |
* @access public |
|---|
| 773 |
* @return void |
|---|
| 774 |
*/ |
|---|
| 775 |
public function addObjectTag($label, $formHelper, $object, $method, $tagOptions = array(), $defaultValue = null, $options = array()) |
|---|
| 776 |
{ |
|---|
| 777 |
$tagOptions = _parse_attributes($tagOptions); |
|---|
| 778 |
$options = _parse_attributes($options); |
|---|
| 779 |
|
|---|
| 780 |
|
|---|
| 781 |
if( !strstr($formHelper, 'object_') ) |
|---|
| 782 |
{ |
|---|
| 783 |
$formHelper = 'object_'.$formHelper; |
|---|
| 784 |
} |
|---|
| 785 |
|
|---|
| 786 |
use_helper('Object'); |
|---|
| 787 |
|
|---|
| 788 |
|
|---|
| 789 |
$options['control_name'] = _convert_method_to_name($method, $options); |
|---|
| 790 |
|
|---|
| 791 |
$element = array('label' => $label, 'name' => $options['control_name'], 'form_helper' => $formHelper, 'helper_arguments' => array('object' => $object, array('get', array($options['control_name'])), 'options' => $tagOptions, 'default_value' => $defaultValue), 'options' => $options); |
|---|
| 792 |
|
|---|
| 793 |
$this->addRawElement($element); |
|---|
| 794 |
} |
|---|
| 795 |
|
|---|
| 796 |
|
|---|
| 797 |
* Add Content Getter |
|---|
| 798 |
* |
|---|
| 799 |
* Add an element to the form that uses the sfContentGetter plugin to pull in content from anywhere in symfony |
|---|
| 800 |
* |
|---|
| 801 |
* <code> |
|---|
| 802 |
* $sfFormBuilder->addContentGetter('Content Getter', 'content_getter_string'); |
|---|
| 803 |
* </code> |
|---|
| 804 |
* |
|---|
| 805 |
* @param mixed $label |
|---|
| 806 |
* @param mixed $content |
|---|
| 807 |
* @param array $vars |
|---|
| 808 |
* @access public |
|---|
| 809 |
* @return void |
|---|
| 810 |
*/ |
|---|
| 811 |
public function addContentGetter($label, $name, $content, $getterOptions = array(), $options = array()) |
|---|
| 812 |
{ |
|---|
| 813 |
$element = array('label' => $label, 'form_helper' => 'content_getter', 'helper_arguments' => array('content' => $content, 'options' => $getterOptions, 'current_module' => $this->getModuleName()), 'name' => $name, 'options' => $options); |
|---|
| 814 |
|
|---|
| 815 |
$this->addRawElement($element); |
|---|
| 816 |
} |
|---|
| 817 |
|
|---|
| 818 |
|
|---|
| 819 |
* Add Filler |
|---|
| 820 |
* |
|---|
| 821 |
* Add a blank form element "filler" to the elements. Takes up the space of an element, but is blank. |
|---|
| 822 |
* |
|---|
| 823 |
* <code> |
|---|
| 824 |
* $sfFormBuilder->addFiller(); |
|---|
| 825 |
* </code> |
|---|
| 826 |
* |
|---|
| 827 |
* @access public |
|---|
| 828 |
* @return void |
|---|
| 829 |
*/ |
|---|
| 830 |
public function addFiller() |
|---|
| 831 |
{ |
|---|
| 832 |
$this->incrementFillerCount(); |
|---|
| 833 |
|
|---|
| 834 |
$currentElementGroup = $this->getCurrentElementGroup(); |
|---|
| 835 |
$element['group'] = $currentElementGroup; |
|---|
| 836 |
$key = 'filler_'.$this->getFillerCount(); |
|---|
| 837 |
$element['name'] = $key; |
|---|
| 838 |
$element['label'] = ' '; |
|---|
| 839 |
$element['form_helper'] = 'content_getter'; |
|---|
| 840 |
$element['helper_arguments']['content'] = ' '; |
|---|
| 841 |
$element['helper_arguments']['current_module'] = $this->getModuleName(); |
|---|
| 842 |
$element['helper_arguments']['options'] = array(); |
|---|
| 843 |
$element['label_style'] = $this->getLabelStyle(); |
|---|
| 844 |
$element['number_of_element_columns'] = $this->getNumberOfElementColumns(); |
|---|
| 845 |
$element['options'] = array(); |
|---|
| 846 |
|
|---|
| 847 |
$this->elements[$currentElementGroup][$key] = $element; |
|---|
| 848 |
} |
|---|
| 849 |
|
|---|
| 850 |
|
|---|
| 851 |
* Add Form Builder Input Tag |
|---|
| 852 |
* |
|---|
| 853 |
* Add a form builder element that uses the input_tag form helper |
|---|
| 854 |
* |
|---|
| 855 |
* <code> |
|---|
| 856 |
* $sfFormBuilder->addInputTag('Input Tag', 'input_tag', 'default value'); |
|---|
| 857 |
* </code> |
|---|
| 858 |
* |
|---|
| 859 |
* @param string $label Label for the input tag |
|---|
| 860 |
* @param string $name Name of the input tag |
|---|
| 861 |
* @param string $value Value of the input tag |
|---|
| 862 |
* @param mixed $tagOptions Array/string of options accepted by the input_tag form helper |
|---|
| 863 |
* @param mixed $options Array/string of options for the form element |
|---|
| 864 |
* @access public |
|---|
| 865 |
* @return void |
|---|
| 866 |
*/ |
|---|
| 867 |
public function addInputTag($label, $name, $value = null, $tagOptions = array(), $options = array()) |
|---|
| 868 |
{ |
|---|
| 869 |
$tagOptions = _parse_attributes($tagOptions); |
|---|
| 870 |
|
|---|
| 871 |
$this->addElement('input_tag', $label, array('name' => $name, 'value' => $value, 'options' => $tagOptions), $options); |
|---|
| 872 |
} |
|---|
| 873 |
|
|---|
| 874 |
|
|---|
| 875 |
* Add Form Builder Checkbox Tag |
|---|
| 876 |
* |
|---|
| 877 |
* Add a form builder element that uses the checkbox_tag form helper |
|---|
| 878 |
* |
|---|
| 879 |
* <code> |
|---|
| 880 |
* $sfFormBuilder->addCheckboxTag('Checkbox', 'checkbox', 1, false); |
|---|
| 881 |
* </code> |
|---|
| 882 |
* |
|---|
| 883 |
* @param string $label Label for the checkbox tag |
|---|
| 884 |
* @param mixed $name Name of the checkbox tag |
|---|
| 885 |
* @param string $value Value of the checkbox tag |
|---|
| 886 |
* @param bool $checked Whether or not the checkbox is checked |
|---|
| 887 |
* @param mixed $options Array/string of options accepted by the checkbox_tag form helper |
|---|
| 888 |
* @access public |
|---|
| 889 |
* @return void |
|---|
| 890 |
*/ |
|---|
| 891 |
public function addCheckboxTag($label, $name, $value = '1', $checked = false, $tagOptions = array(), $options = array()) |
|---|
| 892 |
{ |
|---|
| 893 |
$tagOptions = _parse_attributes($tagOptions); |
|---|
| 894 |
|
|---|
| 895 |
$this->addElement('checkbox_tag', $label, array('name' => $name, 'value' => $value, 'checked' => $checked, 'options' => $tagOptions), $options); |
|---|
| 896 |
} |
|---|
| 897 |
|
|---|
| 898 |
|
|---|
| 899 |
* Add Form Builder Input Date Range Tag |
|---|
| 900 |
* |
|---|
| 901 |
* Add a form builder element that uses the input_date_range_tag form helper |
|---|
| 902 |
* |
|---|
| 903 |
* <code> |
|---|
| 904 |
* $sfFormBuilder->addInputDateRangeTag('Input Date Range Tag', 'date', 'from=0000-00-00 to=0000-00-00'); |
|---|
| 905 |
* </code> |
|---|
| 906 |
* |
|---|
| 907 |
* @param string $label Label for the input date range tag |
|---|
| 908 |
* @param mixed $name Name of the input date range tag |
|---|
| 909 |
* @param mixed $value Value of the input date range tag |
|---|
| 910 |
* @param string $tagOptions Array/string of options accepted by the input_date_range_tag form helper |
|---|
| 911 |
* @param string $options Array/string of options for |
|---|
| 912 |
* @access public |
|---|
| 913 |
* @return void |
|---|
| 914 |
*/ |
|---|
| 915 |
public function addInputDateRangeTag($label, $name, $value, $tagOptions = array(), $options = array()) |
|---|
| 916 |
{ |
|---|
| 917 |
$tagOptions = _parse_attributes($tagOptions); |
|---|
| 918 |
|
|---|
| 919 |
$this->addElement('input_date_range_tag', $label, array('name' => $name, 'value' => $value, 'options' => $tagOptions), $options); |
|---|
| 920 |
} |
|---|
| 921 |
|
|---|
| 922 |
|
|---|
| 923 |
* Add Form Builder Input Date Tag |
|---|
| 924 |
* |
|---|
| 925 |
* Add a form builder element that uses the input_date_tag form helper |
|---|
| 926 |
* |
|---|
| 927 |
* <code> |
|---|
| 928 |
* $sfFormBuilder->addInputDateTag('Input Date Tag', 'date', '0000-00-00'); |
|---|
| 929 |
* </code> |
|---|
| 930 |
* |
|---|
| 931 |
* @param string $label Label for the input_date_tag |
|---|
| 932 |
* @param string $name Name of the input_date_tag |
|---|
| 933 |
* @param string $value Value of the input_date_tag |
|---|
| 934 |
* @param mixed $options Array/string of options accepted by the input_date_tag form helper |
|---|
| 935 |
* @access public |
|---|
| 936 |
* @return void |
|---|
| 937 |
*/ |
|---|
| 938 |
public function addInputDateTag($label, $name, $value = null, $tagOptions = array(), $options = array()) |
|---|
| 939 |
{ |
|---|
| 940 |
$tagOptions = _parse_attributes($tagOptions); |
|---|
| 941 |
|
|---|
| 942 |
$this->addElement('input_date_tag', $label, array('name' => $name, 'value' => $value, 'options' => $tagOptions), $options); |
|---|
| 943 |
} |
|---|
| 944 |
|
|---|
| 945 |
|
|---|
| 946 |
* Add Form Builder Input File Tag |
|---|
| 947 |
* |
|---|
| 948 |
* Add a form builder element that uses the input_file_tag form helper |
|---|
| 949 |
* |
|---|
| 950 |
* <code> |
|---|
| 951 |
* $sfFormBuilder->addInputFileTag('File', 'file1'); |
|---|
| 952 |
* </code> |
|---|
| 953 |
* |
|---|
| 954 |
* @param string $label Label for the input_file_tag |
|---|
| 955 |
* @param string $name Name of the input_file_tag |
|---|
| 956 |
* @param mixed $options Array/string of options accepted by the input_file_tag |
|---|
| 957 |
* @access public |
|---|
| 958 |
* @return void |
|---|
| 959 |
*/ |
|---|
| 960 |
public function addInputFileTag($label, $name, $tagOptions = array(), $options = array()) |
|---|
| 961 |
{ |
|---|
| 962 |
$tagOptions = _parse_attributes($tagOptions); |
|---|
| 963 |
|
|---|
| 964 |
$this->addElement('input_file_tag', $label, array('name' => $name, 'options' => $tagOptions), $options); |
|---|
| 965 |
|
|---|
| 966 |
|
|---|
| 967 |
$this->enableFileUploading(); |
|---|
| 968 |
} |
|---|
| 969 |
|
|---|
| 970 |
|
|---|
| 971 |
* Add Form Builder Input Password Tag |
|---|
| 972 |
* |
|---|
| 973 |
* Add a form builder element that uses the input_password_tag form helper |
|---|
| 974 |
* |
|---|
| 975 |
* <code> |
|---|
| 976 |
* $sfFormBuilder->addInputPasswordTag('Password', 'password'); |
|---|
| 977 |
* </coe> |
|---|
| 978 |
* |
|---|
| 979 |
* @param string $label Label for the input_password_tag |
|---|
| 980 |
* @param string $name Name of the input_password_tag |
|---|
| 981 |
* @param mixed $value Value of the input_password_tag |
|---|
| 982 |
* @param mixed $options Array/string of options accepted by the input_password_tag |
|---|
| 983 |
* @access public |
|---|
| 984 |
* @return void |
|---|
| 985 |
*/ |
|---|
| 986 |
public function addInputPasswordTag($label, $name = 'password', $value = null, $tagOptions = array(), $options = array()) |
|---|
| 987 |
{ |
|---|
| 988 |
$tagOptions = _parse_attributes($tagOptions); |
|---|
| 989 |
|
|---|
| 990 |
$this->addElement('input_password_tag', $label, array('name' => $name, 'value' => $value, 'options' => $tagOptions), $options); |
|---|
| 991 |
} |
|---|
| 992 |
|
|---|
| 993 |
|
|---|
| 994 |
* Add Form Builder Radio Button Tag |
|---|
| 995 |
* |
|---|
| 996 |
* Add a form builder element that uses the radio_button_tag form helper |
|---|
| 997 |
* |
|---|
| 998 |
* <code> |
|---|
| 999 |
* $sfFormBuilder->addRadioButtonTag('Radio Button', 'radio', 'value', false); |
|---|
| 1000 |
* </code> |
|---|
| 1001 |
* |
|---|
| 1002 |
* @param string $label Label for the radio button tag |
|---|
| 1003 |
* @param string $name Name of the radio button tag |
|---|
| 1004 |
* @param string $value Value of the radio button tag |
|---|
| 1005 |
* @param bool $checked Whether or not the radio is checked |
|---|
| 1006 |
* @param string $options Array/string of options accepted by the radio_button_tag |
|---|
| 1007 |
* @access public |
|---|
| 1008 |
* @return void |
|---|
| 1009 |
*/ |
|---|
| 1010 |
public function addRadioButtonTag($label, $name, $value, $checked = false, $tagOptions = array(), $options = array()) |
|---|
| 1011 |
{ |
|---|
| 1012 |
$tagOptions = _parse_attributes($tagOptions); |
|---|
| 1013 |
|
|---|
| 1014 |
$this->addElement('radiobutton_tag', $label, array('name' => $name, 'value' => $value, 'checked' => $checked, 'options' => $tagOptions), $options); |
|---|
| 1015 |
} |
|---|
| 1016 |
|
|---|
| 1017 |
|
|---|
| 1018 |
* Add Form Builder Select Country Tag |
|---|
| 1019 |
* |
|---|
| 1020 |
* Add a form builder element that uses the select_country_tag form helper |
|---|
| 1021 |
* |
|---|
| 1022 |
* <code> |
|---|
| 1023 |
* $sfFormBuilder->addSelectCountryTag('Country', 'country', 'US'); |
|---|
| 1024 |
* </code> |
|---|
| 1025 |
* |
|---|
| 1026 |
* @param string $label Label for the select country tag |
|---|
| 1027 |
* @param string $name Name of the selet country tag |
|---|
| 1028 |
* @param string $selected The value/country to auto select |
|---|
| 1029 |
* @param mixed $options Array/string of options accepted by the select_country_tag |
|---|
| 1030 |
* @access public |
|---|
| 1031 |
* @return void |
|---|
| 1032 |
*/ |
|---|
| 1033 |
public function addSelectCountryTag($label, $name, $selected = null, $tagOptions = array(), $options = array()) |
|---|
| 1034 |
{ |
|---|
| 1035 |
$tagOptions = _parse_attributes($tagOptions); |
|---|
| 1036 |
|
|---|
| 1037 |
$this->addElement('select_country_tag', $label, array('name' => $name, 'selected' => $selected, 'options' => $tagOptions), $options); |
|---|
| 1038 |
} |
|---|
| 1039 |
|
|---|
| 1040 |
|
|---|
| 1041 |
* Add Form Builder Select Language Tag |
|---|
| 1042 |
* |
|---|
| 1043 |
* Add a form builder element that uses the select_language_tag form helper |
|---|
| 1044 |
* |
|---|
| 1045 |
* <code> |
|---|
| 1046 |
* $sfFormBuilder->addSelectLanguageTag('Language', 'language', 'English'); |
|---|
| 1047 |
* </code> |
|---|
| 1048 |
* |
|---|
| 1049 |
* @param string $label Label for the select language tag |
|---|
| 1050 |
* @param string $name Name of the select language tag |
|---|
| 1051 |
* @param string $selected Value to pre-select in the language tag |
|---|
| 1052 |
* @param mixed $options Array/string of options accepted by the select_language_tag |
|---|
| 1053 |
* @access public |
|---|
| 1054 |
* @return void |
|---|
| 1055 |
*/ |
|---|
| 1056 |
public function addSelectLanguageTag($label, $name, $selected = null, $tagOptions = array(), $options = array()) |
|---|
| 1057 |
{ |
|---|
| 1058 |
$tagOptions = _parse_attribute($tagOptions); |
|---|
| 1059 |
|
|---|
| 1060 |
$this->addElement('select_language_tag', $label, array('name' => $name, 'selected' => $selected, 'options' => $tagOptions), $options); |
|---|
| 1061 |
} |
|---|
| 1062 |
|
|---|
| 1063 |
|
|---|
| 1064 |
* Add Form Builder Select Tag |
|---|
| 1065 |
* |
|---|
| 1066 |
* Add a form builder element that uses the select_tag form helper |
|---|
| 1067 |
* |
|---|
| 1068 |
* <code> |
|---|
| 1069 |
* // 3rd argument can be a string of html options, or it can accept an array of arguments for the objects_for_select() function in symfony. |
|---|
| 1070 |
* $sfFormBuilder->addSelectTag('Select', 'select', '<option></option>'); |
|---|
| 1071 |
* $sfFormBuilder->addSelectTag('Select, 'select', array($modelArray, 'getValueMethod', 'getTextMethod', 'selected_value')); |
|---|
| 1072 |
* </code> |
|---|
| 1073 |
* |
|---|
| 1074 |
* @param string $label Label for the select tag |
|---|
| 1075 |
* @param string $name Name of the select tag |
|---|
| 1076 |
* @param mixed $option_tags Array of options to be generated using options_for_select() or an already built string of options |
|---|
| 1077 |
* @param mixed $options Array/string of options accepted by the select_tag form helper |
|---|
| 1078 |
* @access public |
|---|
| 1079 |
* @return void |
|---|
| 1080 |
*/ |
|---|
| 1081 |
public function addSelectTag($label, $name, $option_tags = null, $tagOptions = array(), $options = array()) |
|---|
| 1082 |
{ |
|---|
| 1083 |
$tagOptions = _parse_attributes($tagOptions); |
|---|
| 1084 |
|
|---|
| 1085 |
if( is_array($option_tags) ) |
|---|
| 1086 |
{ |
|---|
| 1087 |
$option_tags = call_user_func_array('options_for_select', $option_tags); |
|---|
| 1088 |
} |
|---|
| 1089 |
|
|---|
| 1090 |
$this->addElement('select_tag', $label, array('name' => $name, 'option_tags' => $option_tags, 'options' => $tagOptions), $options); |
|---|
| 1091 |
} |
|---|
| 1092 |
|
|---|
| 1093 |
|
|---|
| 1094 |
* Add Form Builder Text Area Tag |
|---|
| 1095 |
* |
|---|
| 1096 |
* Add form builder element that uses the text_area_tag form helper |
|---|
| 1097 |
* |
|---|
| 1098 |
* <code> |
|---|
| 1099 |
* $sfFormBuilder->addTextAreaTag('Text Area', 'textarea', 'content for text area'); |
|---|
| 1100 |
* </code> |
|---|
| 1101 |
* |
|---|
| 1102 |
* @param string $label Label for the text area |
|---|
| 1103 |
* @param string $name Name of the text area |
|---|
| 1104 |
* @param string $content Content/value of the text area |
|---|
| 1105 |
* @param mixed $options Array/string of options accepted by the textarea_tag helper |
|---|
| 1106 |
* @access public |
|---|
| 1107 |
* @return void |
|---|
| 1108 |
*/ |
|---|
| 1109 |
public function addTextAreaTag($label, $name, $content = null, $tagOptions = array(), $options = array()) |
|---|
| 1110 |
{ |
|---|
| 1111 |
$tagOptions = _parse_attributes($tagOptions); |
|---|
| 1112 |
|
|---|
| 1113 |
$this->addElement('textarea_tag', $label, array('name' => $name, 'content' => $content, 'options' => $tagOptions), $options); |
|---|
| 1114 |
} |
|---|
| 1115 |
|
|---|
| 1116 |
|
|---|
| 1117 |
* Add Form Builder Element |
|---|
| 1118 |
* |
|---|
| 1119 |
* Method used by the other public add form builder element to build and add the element to the base array of elements |
|---|
| 1120 |
* |
|---|
| 1121 |
* @param string $formHelper Name of the form helper to use for this element |
|---|
| 1122 |
* @param string $label Label of the element |
|---|
| 1123 |
* @param array $helperArguments Array of the arguments needed for the helper |
|---|
| 1124 |
* @access protected |
|---|
| 1125 |
* @return void |
|---|
| 1126 |
*/ |
|---|
| 1127 |
protected function addElement($formHelper, $label, $helperArguments, $options = array()) |
|---|
| 1128 |
{ |
|---|
| 1129 |
$element = array('label' => $label, 'name' => $helperArguments['name'], 'form_helper' => $formHelper, 'helper_arguments' => $helperArguments, 'options' => $options); |
|---|
| 1130 |
|
|---|
| 1131 |
$this->addRawElement($element); |
|---|
| 1132 |
} |
|---|
| 1133 |
|
|---|
| 1134 |
|
|---|
| 1135 |
* Add Raw Element |
|---|
| 1136 |
* |
|---|
| 1137 |
* @param mixed $element |
|---|
| 1138 |
* @access protected |
|---|
| 1139 |
* @return void |
|---|
| 1140 |
*/ |
|---|
| 1141 |
protected function addRawElement($element) |
|---|
| 1142 |
{ |
|---|
| 1143 |
$currentElementGroup = $this->getCurrentElementGroup(); |
|---|
| 1144 |
$element['group'] = $currentElementGroup; |
|---|
| 1145 |
$element['label_style'] = $this->getLabelStyle(); |
|---|
| 1146 |
$element['number_of_element_columns'] = $this->getNumberOfElementColumns(); |
|---|
| 1147 |
|
|---|
| 1148 |
$element['options'] = _parse_attributes($element['options']); |
|---|
| 1149 |
|
|---|
| 1150 |
$this->elements[$currentElementGroup][$element['name']] = $element; |
|---|
| 1151 |
} |
|---|
| 1152 |
|
|---|
| 1153 |
|
|---|
| 1154 |
* Set Form Builder Id |
|---|
| 1155 |
* |
|---|
| 1156 |
* Setup the form builder by setting a unique id. Other class values will be set based on this id if they have not been set yet |
|---|
| 1157 |
* |
|---|
| 1158 |
* <code> |
|---|
| 1159 |
* $sfFormBuilder->setId('form_id'); |
|---|
| 1160 |
* </code> |
|---|
| 1161 |
* |
|---|
| 1162 |
* @param string $id |
|---|
| 1163 |
* @access public |
|---|
| 1164 |
* @return void |
|---|
| 1165 |
*/ |
|---|
| 1166 |
public function setId($id) |
|---|
| 1167 |
{ |
|---|
| 1168 |
$this->id = $id; |
|---|
| 1169 |
|
|---|
| 1170 |
if( !$this->getTitle() ) |
|---|
| 1171 |
{ |
|---|
| 1172 |
$this->setTitle(ucwords(sfInflector::humanize($id))); |
|---|
| 1173 |
} |
|---|
| 1174 |
|
|---|
| 1175 |
if( !$this->getName() ) |
|---|
| 1176 |
{ |
|---|
| 1177 |
$this->setName($this->getId().'_form_name'); |
|---|
| 1178 |
} |
|---|
| 1179 |
} |
|---|
| 1180 |
|
|---|
| 1181 |
|
|---|
| 1182 |
* Set Title |
|---|
| 1183 |
* |
|---|
| 1184 |
* <code> |
|---|
| 1185 |
* // Uses sfContentGetter plugin for parsing and rendering the title |
|---|
| 1186 |
* $sfFormBuilder->setTitle('content_getter_string'); |
|---|
| 1187 |
* echo $sfFormBuilder->getRenderedTitle(); // will parse, and return rendered title with sfContentGetter |
|---|
| 1188 |
* </code> |
|---|
| 1189 |
* |
|---|
| 1190 |
* @param mixed $title |
|---|
| 1191 |
* @access public |
|---|
| 1192 |
* @return void |
|---|
| 1193 |
*/ |
|---|
| 1194 |
public function setTitle($title) |
|---|
| 1195 |
{ |
|---|
| 1196 |
if( $title == false ) |
|---|
| 1197 |
{ |
|---|
| 1198 |
$this->setShowTitle(false); |
|---|
| 1199 |
$this->title = null; |
|---|
| 1200 |
} else { |
|---|
| 1201 |
$this->title = $title; |
|---|
| 1202 |
$this->setShowTitle(true); |
|---|
| 1203 |
} |
|---|
| 1204 |
} |
|---|
| 1205 |
|
|---|
| 1206 |
|
|---|
| 1207 |
* Get Form Builder Rendered Title |
|---|
| 1208 |
* |
|---|
| 1209 |
* Process the set title and get the partial, component, or return the title string |
|---|
| 1210 |
* |
|---|
| 1211 |
* <code> |
|---|
| 1212 |
* echo $sfFormBuilder->getRenderedTitle(); |
|---|
| 1213 |
* </code> |
|---|
| 1214 |
* |
|---|
| 1215 |
* @access public |
|---|
| 1216 |
* @return string $title |
|---|
| 1217 |
*/ |
|---|
| 1218 |
public function getRenderedTitle() |
|---|
| 1219 |
{ |
|---|
| 1220 |
return sfContentGetter::getInstance($this->getTitle(), array(), $this->getModuleName())->output(); |
|---|
| 1221 |
} |
|---|
| 1222 |
|
|---|
| 1223 |
|
|---|
| 1224 |
* Add Form Builder Hidden FIeld |
|---|
| 1225 |
* |
|---|
| 1226 |
* Add a form builder hidden field |
|---|
| 1227 |
* |
|---|
| 1228 |
* <code> |
|---|
| 1229 |
* $sfFormBuilder->addHiddenField('name', 'value'); |
|---|
| 1230 |
* </code> |
|---|
| 1231 |
* |
|---|
| 1232 |
* @param string $name Name of the hidden field |
|---|
| 1233 |
* @param string $value Value of the hidden field |
|---|
| 1234 |
* @access public |
|---|
| 1235 |
* @return void |
|---|
| 1236 |
*/ |
|---|
| 1237 |
public function addHiddenField($name, $value) |
|---|
| 1238 |
{ |
|---|
| 1239 |
$this->hiddenFields[$name] = $value; |
|---|
| 1240 |
} |
|---|
| 1241 |
|
|---|
| 1242 |
|
|---|
| 1243 |
* Add Form Builder Submit Button |
|---|
| 1244 |
* |
|---|
| 1245 |
* Add a submit button to the form builder |
|---|
| 1246 |
* |
|---|
| 1247 |
* <code> |
|---|
| 1248 |
* // uses symfony submit_tag() so 2nd argument can be an array or string of options |
|---|
| 1249 |
* $sfFormBuilder->addSubmitButton('name'); |
|---|
| 1250 |
* </code> |
|---|
| 1251 |
* |
|---|
| 1252 |
* @param string $name Name of the submit button |
|---|
| 1253 |
* @param mixed $options Array/string of options accepted by the submit_tag form helper |
|---|
| 1254 |
* @access public |
|---|
| 1255 |
* @return void |
|---|
| 1256 |
*/ |
|---|
| 1257 |
public function addSubmitButton($name, $options = array()) |
|---|
| 1258 |
{ |
|---|
| 1259 |
$options = _parse_attributes($options); |
|---|
| 1260 |
$options['value'] = array_key_exists('value', $options) ? $options['value']:sfInflector::humanize($name); |
|---|
| 1261 |
$options['name'] = $name; |
|---|
| 1262 |
|
|---|
| 1263 |
$this->submitButtons[$name] = $options; |
|---|
| 1264 |
} |
|---|
| 1265 |
|
|---|
| 1266 |
|
|---|
| 1267 |
* Get Form Builder Header Html |
|---|
| 1268 |
* |
|---|
| 1269 |
* Get the form header html, includes hidden fields and opening <form> tag |
|---|
| 1270 |
* |
|---|
| 1271 |
* @access public |
|---|
| 1272 |
* @return string $html |
|---|
| 1273 |
*/ |
|---|
| 1274 |
public function getHeaderHtml() |
|---|
| 1275 |
{ |
|---|
| 1276 |
$html = "\n\n".'<form name="'.$this->getName().'" id="'.$this->getId().'" action="'.sfContext::getInstance()->getController()->genUrl($this->getAction()).'" method="'.$this->getActionMethod().'" '.$this->getExtra().'>'; |
|---|
| 1277 |
$html .= $this->getHiddenFieldsHtml()."\n"; |
|---|
| 1278 |
|
|---|
| 1279 |
return $html; |
|---|
| 1280 |
} |
|---|
| 1281 |
|
|---|
| 1282 |
|
|---|
| 1283 |
* Ge Form Builder Hidden Fields html |
|---|
| 1284 |
* |
|---|
| 1285 |
* Loop over array of hidden fields and generate html |
|---|
| 1286 |
* |
|---|
| 1287 |
* @access public |
|---|
| 1288 |
* @return string $html |
|---|
| 1289 |
*/ |
|---|
| 1290 |
public function getHiddenFieldsHtml() |
|---|
| 1291 |
{ |
|---|
| 1292 |
$hiddenFields = $this->getHiddenFields(); |
|---|
| 1293 |
|
|---|
| 1294 |
if( is_array($hiddenFields) AND !empty($hiddenFields) ) |
|---|
| 1295 |
{ |
|---|
| 1296 |
$html = ''; |
|---|
| 1297 |
foreach($hiddenFields AS $name => $value) |
|---|
| 1298 |
{ |
|---|
| 1299 |
$html .= '<input type="hidden" name="'.$name.'" value="'.$value.'" />'."\n"; |
|---|
| 1300 |
} |
|---|
| 1301 |
|
|---|
| 1302 |
return $html; |
|---|
| 1303 |
} |
|---|
| 1304 |
} |
|---|
| 1305 |
|
|---|
| 1306 |
|
|---|
| 1307 |
* Get Form Builder Footer Html |
|---|
| 1308 |
* |
|---|
| 1309 |
* Get the html for the form builder footer. Inlcudes submit buttons and closing form tag |
|---|
| 1310 |
* |
|---|
| 1311 |
* @access public |
|---|
| 1312 |
* @return void |
|---|
| 1313 |
*/ |
|---|
| 1314 |
public function getFooterRowHtml() |
|---|
| 1315 |
{ |
|---|
| 1316 |
$html = ''; |
|---|
| 1317 |
|
|---|
| 1318 |
if( $this->getShowFooter() ) |
|---|
| 1319 |
{ |
|---|
| 1320 |
if( $this->getFooterRowContentGetter() ) |
|---|
| 1321 |
{ |
|---|
| 1322 |
$html .= sfContentGetter::getInstance($this->getFooterRowContentGetter(), array('formBuilder' => $this), $this->getModuleName())->output(); |
|---|
| 1323 |
} else { |
|---|
| 1324 |
$html .= "\n\n".'<div class="form_builder_footer" id="'.$this->getId().'_footer">'."\n"; |
|---|
| 1325 |
|
|---|
| 1326 |
if( $this->getShowSubmitButtons() ) |
|---|
| 1327 |
{ |
|---|
| 1328 |
$html .= $this->getSubmitButtonsHtml(); |
|---|
| 1329 |
} |
|---|
| 1330 |
|
|---|
| 1331 |
$html .= '</div>'."\n\n"; |
|---|
| 1332 |
} |
|---|
| 1333 |
} |
|---|
| 1334 |
|
|---|
| 1335 |
$html .= '</form>'."\n\n"; |
|---|
| 1336 |
|
|---|
| 1337 |
return $html; |
|---|
| 1338 |
} |
|---|
| 1339 |
|
|---|
| 1340 |
|
|---|
| 1341 |
* getSubmitButtonsHtml |
|---|
| 1342 |
* |
|---|
| 1343 |
* @access public |
|---|
| 1344 |
* @return void |
|---|
| 1345 |
*/ |
|---|
| 1346 |
public function getSubmitButtonsHtml() |
|---|
| 1347 |
{ |
|---|
| 1348 |
$submitButtons = $this->getSubmitButtons(); |
|---|
| 1349 |
|
|---|
| 1350 |
if( is_array($submitButtons) AND !empty($submitButtons) ) |
|---|
| 1351 |
{ |
|---|
| 1352 |
$html = ''; |
|---|
| 1353 |
foreach($submitButtons AS $name => $options) |
|---|
| 1354 |
{ |
|---|
| 1355 |
$options['name'] = $name; |
|---|
| 1356 |
$options['class'] = 'button'; |
|---|
| 1357 |
$html .= submit_tag($options['value'], $options); |
|---|
| 1358 |
} |
|---|
| 1359 |
|
|---|
| 1360 |
$output = "\t".'<div class="form_builder_footer_submit_buttons" id="'.$this->getId().'_footer_submit_buttons">'."\n"; |
|---|
| 1361 |
$output .= "\t\t".$html; |
|---|
| 1362 |
$output .= "\n\t".'</div>'."\n"; |
|---|
| 1363 |
|
|---|
| 1364 |
return $output; |
|---|
| 1365 |
} |
|---|
| 1366 |
} |
|---|
| 1367 |
|
|---|
| 1368 |
|
|---|
| 1369 |
* Generate Form Builder |
|---|
| 1370 |
* |
|---|
| 1371 |
* Alias to generate the form builder, calls generateHtml() |
|---|
| 1372 |
* |
|---|
| 1373 |
* @access public |
|---|
| 1374 |
* @return void |
|---|
| 1375 |
*/ |
|---|
| 1376 |
public function generate() |
|---|
| 1377 |
{ |
|---|
| 1378 |
$this->generateHtml(); |
|---|
| 1379 |
} |
|---|
| 1380 |
|
|---|
| 1381 |
|
|---|
| 1382 |
* Get Form Builder Element Input |
|---|
| 1383 |
* |
|---|
| 1384 |
* Get the input part of a form element. Will either be a partial, component, or a form helper |
|---|
| 1385 |
* |
|---|
| 1386 |
* @param array $element Array of element properties for the element input |
|---|
| 1387 |
* @param array $helperArguments Array of arguments for the helper |
|---|
| 1388 |
* @access public |
|---|
| 1389 |
* @return void |
|---|
| 1390 |
*/ |
|---|
| 1391 |
public function getElementInput($element, $helperArguments) |
|---|
| 1392 |
{ |
|---|
| 1393 |
|
|---|
| 1394 |
$request = $this->getRequest(); |
|---|
| 1395 |
|
|---|
| 1396 |
$formHelper = _get_option($element, 'form_helper'); |
|---|
| 1397 |
|
|---|
| 1398 |
if( $this->getFillInForm() AND $request->hasParameter($element['name']) AND !strstr($formHelper, 'password') ) |
|---|
| 1399 |
{ |
|---|
| 1400 |
if( $formHelper == 'checkbox_tag' ) |
|---|
| 1401 |
{ |
|---|
| 1402 |
$helperArguments['checked'] = $request->getParameter($element['name']) == $helperArguments['value'] ? true:false; |
|---|
| 1403 |
} else { |
|---|
| 1404 |
$helperArguments['value'] = $request->getParameter($element['name']); |
|---|
| 1405 |
$helperArguments['default_value'] = $helperArguments['value']; |
|---|
| 1406 |
} |
|---|
| 1407 |
} |
|---|
| 1408 |
|
|---|
| 1409 |
if( $formHelper == 'content_getter' ) |
|---|
| 1410 |
{ |
|---|
| 1411 |
$vars = array_merge($helperArguments['options'], array('name' => $element['name'])); |
|---|
| 1412 |
return sfContentGetter::getInstance($helperArguments['content'], $vars, $helperArguments['current_module'])->output(); |
|---|
| 1413 |
} |
|---|
| 1414 |
else |
|---|
| 1415 |
{ |
|---|
| 1416 |
if( $formHelper ) |
|---|
| 1417 |
{ |
|---|
| 1418 |
if( function_exists($formHelper) ) |
|---|
| 1419 |
{ |
|---|
| 1420 |
|
|---|
| 1421 |
if( array_key_exists('object', $helperArguments) && $helperArguments['object'] && !is_object($helperArguments['object']) ) |
|---|
| 1422 |
{ |
|---|
| 1423 |
$object = $helperArguments['object']; |
|---|
| 1424 |
|
|---|
| 1425 |
|
|---|
| 1426 |
if( class_exists($object) ) |
|---|
| 1427 |
{ |
|---|
| 1428 |
$helperArguments['object'] = new $object(); |
|---|
| 1429 |
} else { |
|---|
| 1430 |
throw new Exception($object." class could not be found. Please pass a valid model name or an already instantiated model"); |
|---|
| 1431 |
} |
|---|
| 1432 |
} |
|---|
| 1433 |
|
|---|
| 1434 |
$formElement = call_user_func_array($formHelper, $helperArguments); |
|---|
| 1435 |
} else { |
|---|
| 1436 |
throw new Exception("$formHelper does not exist"); |
|---|
| 1437 |
} |
|---|
| 1438 |
|
|---|
| 1439 |
return $formElement; |
|---|
| 1440 |
} |
|---|
| 1441 |
} |
|---|
| 1442 |
} |
|---|
| 1443 |
|
|---|
| 1444 |
|
|---|
| 1445 |
* Get Form Builder Element Label |
|---|
| 1446 |
* |
|---|
| 1447 |
* Get the label html for a form element |
|---|
| 1448 |
* |
|---|
| 1449 |
* @param string $name Name of the <label> tag |
|---|
| 1450 |
* @param string $label Label/value to put in <label> tag |
|---|
| 1451 |
* @access public |
|---|
| 1452 |
* @return string $html |
|---|
| 1453 |
*/ |
|---|
| 1454 |
public function getElementLabel($name, $label) |
|---|
| 1455 |
{ |
|---|
| 1456 |
if( $label ) |
|---|
| 1457 |
{ |
|---|
| 1458 |
$options = 'accesskey='.strtolower($label[0]); |
|---|
| 1459 |
|
|---|
| 1460 |
$label = sfContentGetter::getInstance($label, array(), $this->getModuleName())->output(); |
|---|
| 1461 |
|
|---|
| 1462 |
return label_for($name, $label, $options); |
|---|
| 1463 |
} |
|---|
| 1464 |
} |
|---|
| 1465 |
|
|---|
| 1466 |
|
|---|
| 1467 |
* getElementHelp |
|---|
| 1468 |
* |
|---|
| 1469 |
* @param mixed $element |
|---|
| 1470 |
* @access public |
|---|
| 1471 |
* @return void |
|---|
| 1472 |
*/ |
|---|
| 1473 |
public function getElementHelp($fieldName, $options) |
|---|
| 1474 |
{ |
|---|
| 1475 |
if( array_key_exists('help', $options) ) |
|---|
| 1476 |
{ |
|---|
| 1477 |
return '<span class="form_builder_help_icon" onMouseOver="javascript: document.getElementById(\''.$fieldName.'_help\').className = \'form_builder_help_box_show\';" onMouseOut="javascript: document.getElementById(\''.$fieldName.'_help\').className = \'form_builder_help_box\';">?</span> <span id="'.$fieldName.'_help" class="form_builder_help_box">'.$options['help'].'</span>'; |
|---|
| 1478 |
} |
|---|
| 1479 |
} |
|---|
| 1480 |
|
|---|
| 1481 |
|
|---|
| 1482 |
|
|---|
| 1483 |
* Has Elements |
|---|
| 1484 |
* |
|---|
| 1485 |
* Returns true/false for whether or not the form builder has any elements |
|---|
| 1486 |
* |
|---|
| 1487 |
* @access public |
|---|
| 1488 |
* @return bool |
|---|
| 1489 |
*/ |
|---|
| 1490 |
public function hasElements() |
|---|
| 1491 |
{ |
|---|
| 1492 |
return (isset($this->elements) AND !empty($this->elements) ) ? true:false; |
|---|
| 1493 |
} |
|---|
| 1494 |
|
|---|
| 1495 |
|
|---|
| 1496 |
* Get Form Builder Elements Html |
|---|
| 1497 |
* |
|---|
| 1498 |
* Loop over all the form builder elements and generate the majority of the form |
|---|
| 1499 |
* |
|---|
| 1500 |
* @access public |
|---|
| 1501 |
* @return string $formElementHtml |
|---|
| 1502 |
*/ |
|---|
| 1503 |
public function getElementsHtml() |
|---|
| 1504 |
{ |
|---|
| 1505 |
$formElementsHtml = ''; |
|---|
| 1506 |
$formElementsHtml .= $this->getHeaderHtml(); |
|---|
| 1507 |
|
|---|
| 1508 |
$groups = $this->getElements(); |
|---|
| 1509 |
|
|---|
| 1510 |
$count = 0; |
|---|
| 1511 |
foreach($groups AS $group => $elements) |
|---|
| 1512 |
{ |
|---|
| 1513 |
$formElementsHtml .= $this->getElementGroupHeaderHtml($group); |
|---|
| 1514 |
|
|---|
| 1515 |
$groupElements = ''; |
|---|
| 1516 |
foreach($elements AS $element) |
|---|
| 1517 |
{ |
|---|
| 1518 |
$count++; |
|---|
| 1519 |
$groupElements .= $this->getElementHtml($element, $count); |
|---|
| 1520 |
} |
|---|
| 1521 |
|
|---|
| 1522 |
if( $this->getGroupsCollapsible() AND $group AND $this->getShowElementGroups() ) |
|---|
| 1523 |
{ |
|---|
| 1524 |
$formElementsHtml .= sfCollapsibleContent::wrapContent($this->getId().'_element_group_'.$group, $groupElements); |
|---|
| 1525 |
} else { |
|---|
| 1526 |
$formElementsHtml .= $groupElements; |
|---|
| 1527 |
} |
|---|
| 1528 |
|
|---|
| 1529 |
$formElementsHtml .= $this->getElementGroupFooterHtml($group); |
|---|
| 1530 |
} |
|---|
| 1531 |
|
|---|
| 1532 |
$formElementsHtml .= $this->getFooterRowHtml(); |
|---|
| 1533 |
|
|---|
| 1534 |
return $formElementsHtml; |
|---|
| 1535 |
} |
|---|
| 1536 |
|
|---|
| 1537 |
public function getElementHtml($element, $count) |
|---|
| 1538 |
{ |
|---|
| 1539 |
$numberOfElementColumns = $element['number_of_element_columns']; |
|---|
| 1540 |
$labelStyle = $element['label_style']; |
|---|
| 1541 |
|
|---|
| 1542 |
$helperArguments = _get_option($element, 'helper_arguments', array()); |
|---|
| 1543 |
|
|---|
| 1544 |
$elementInput = $this->getElementInput($element, $helperArguments); |
|---|
| 1545 |
|
|---|
| 1546 |
$fieldName = _get_option($element, 'name'); |
|---|
| 1547 |
$label = _get_option($element, 'label'); |
|---|
| 1548 |
$required = _get_option($element['options'], 'required'); |
|---|
| 1549 |
|
|---|
| 1550 |
$passHelperArguments = $helperArguments; |
|---|
| 1551 |
|
|---|
| 1552 |
$helperArgumentName = _get_option($helperArguments, 'name'); |
|---|
| 1553 |
|
|---|
| 1554 |
$formElementsHtml = "\t".'<div class="form_builder_row_'.$numberOfElementColumns.'" id="'.$this->getId().'_row_'.$fieldName.'">'."\n"; |
|---|
| 1555 |
|
|---|
| 1556 |
$formElementsHtml .= "\t\t".'<div class="form_builder_row_element" id="'.$this->getId().'_row_element_'.$fieldName.'">'."\n"; |
|---|
| 1557 |
|
|---|
| 1558 |
$error = sfContext::getInstance()->getRequest()->hasError($fieldName) ? true:false; |
|---|
| 1559 |
|
|---|
| 1560 |
$errorHtml = ''; |
|---|
| 1561 |
if( $error ) |
|---|
| 1562 |
{ |
|---|
| 1563 |
$errorHtml = '<span class="form_builder_error_'.$labelStyle.'"><span class="error_icon" onMouseOver="javascript: document.getElementById(\''.$fieldName.'_error_holder\').style.display = \'block\';" onMouseOut="javascript: document.getElementById(\''.$fieldName.'_error_holder\').style.display = \'none\';">?</span><span class="error_holder" id="'.$fieldName.'_error_holder">'.sfContext::getInstance()->getRequest()->getError($fieldName).'</span></span>'; |
|---|
| 1564 |
} else { |
|---|
| 1565 |
if( $required ) |
|---|
| 1566 |
{ |
|---|
| 1567 |
$errorHtml = '<font style="font-weight: bold; color: red;">*</font>'; |
|---|
| 1568 |
} |
|---|
| 1569 |
} |
|---|
| 1570 |
|
|---|
| 1571 |
$labelWidth = ''; |
|---|
| 1572 |
if( $width = $this->getLabelWidth() ) |
|---|
| 1573 |
{ |
|---|
| 1574 |
$labelWidth = ' style="width: '.$width.';"'; |
|---|
| 1575 |
} |
|---|
| 1576 |
|
|---|
| 1577 |
$formElementsHtml .= "\t\t\t".'<div '.$labelWidth.' class="form_builder_element_label_'.$labelStyle.'" id="'.$this->getId().'_row_element_label_'.$fieldName.'">'.$this->getElementHelp($fieldName, $element['options']).$this->getElementLabel($fieldName, $label)." ".$errorHtml."</div>\n"; |
|---|
| 1578 |
$formElementsHtml .= "\t\t\t".'<div class="form_builder_element_input_'.$labelStyle.'" id="'.$this->getId().'_row_element_input_'.$fieldName.'">'.$elementInput.'</div>'."\n"; |
|---|
| 1579 |
|
|---|
| 1580 |
$formElementsHtml .= "\t\t</div>\n"; |
|---|
| 1581 |
|
|---|
| 1582 |
$formElementsHtml .= "\t".'</div>'."\n"; |
|---|
| 1583 |
|
|---|
| 1584 |
return $formElementsHtml; |
|---|
| 1585 |
} |
|---|
| 1586 |
|
|---|
| 1587 |
public function getElementGroupHeaderHtml($group) |
|---|
| 1588 |
{ |
|---|
| 1589 |
$title = "\n".'<fieldset class="form_builder_field_set" id="'.$this->getId().'_field_set_'.$group.'">'."\n"; |
|---|
| 1590 |
|
|---|
| 1591 |
if( $group ) |
|---|
| 1592 |
{ |
|---|
| 1593 |
$options = $this->elementGroups[$group]; |
|---|
| 1594 |
$options['title'] = sfContentGetter::getInstance($options['title'], array(), $this->getModuleName())->output(); |
|---|
| 1595 |
|
|---|
| 1596 |
$title .= "<legend>\n"; |
|---|
| 1597 |
$title .= $this->getElementHelp($group, $options); |
|---|
| 1598 |
if( $this->getGroupsCollapsible() ) |
|---|
| 1599 |
{ |
|---|
| 1600 |
$title .= sfCollapsibleContent::getWrapperController($this->getId().'_element_group_'.$group, null, $options['title']); |
|---|
| 1601 |
} else { |
|---|
| 1602 |
$title = $options['title']; |
|---|
| 1603 |
} |
|---|
| 1604 |
|
|---|
| 1605 |
$title .= "\n</legend>\n"; |
|---|
| 1606 |
} |
|---|
| 1607 |
|
|---|
| 1608 |
return $title; |
|---|
| 1609 |
} |
|---|
| 1610 |
|
|---|
| 1611 |
public function getElementGroupFooterHtml() |
|---|
| 1612 |
{ |
|---|
| 1613 |
return "</fieldset>\n"; |
|---|
| 1614 |
} |
|---|
| 1615 |
|
|---|
| 1616 |
|
|---|
| 1617 |
* Get Form Builder Collapse Icon Html |
|---|
| 1618 |
* |
|---|
| 1619 |
* Get the html block for the form builder collapse icon |
|---|
| 1620 |
* |
|---|
| 1621 |
* @access public |
|---|
| 1622 |
* @return string $html |
|---|
| 1623 |
*/ |
|---|
| 1624 |
public function getCollapseIconHtml() |
|---|
| 1625 |
{ |
|---|
| 1626 |
if( $this->getCollapsible() ) |
|---|
| 1627 |
{ |
|---|
| 1628 |
return '<div class="form_builder_collapse_icon">'.sfCollapsibleContent::getWrapperController($this->getId(), $this->isCollapsed()).'</div>'; |
|---|
| 1629 |
} |
|---|
| 1630 |
} |
|---|
| 1631 |
|
|---|
| 1632 |
|
|---|
| 1633 |
* Get Form Builder Title Row |
|---|
| 1634 |
* |
|---|
| 1635 |
* Get the html for the form builder title row |
|---|
| 1636 |
* |
|---|
| 1637 |
* @access public |
|---|
| 1638 |
* @return string $html |
|---|
| 1639 |
*/ |
|---|
| 1640 |
public function getTitleRow() |
|---|
| 1641 |
{ |
|---|
| 1642 |
if( $this->getTitleRowContentGetter() ) |
|---|
| 1643 |
{ |
|---|
| 1644 |
return sfContentGetter::getInstance($this->getTitleRowContentGetter(), array('formBuilder' => $this), $this->getModuleName())->output(); |
|---|
| 1645 |
} else { |
|---|
| 1646 |
return '<div class="form_builder_title_row" id="'.$this->getId().'_title_row">'.$this->getCollapseIconHtml().'<div id="form_builder_title_wrapper">'.$this->getRenderedTitle($this->getTitle()).'</div></div>'; |
|---|
| 1647 |
} |
|---|
| 1648 |
} |
|---|
| 1649 |
|
|---|
| 1650 |
|
|---|
| 1651 |
* Generate Form Builder Html |
|---|
| 1652 |
* |
|---|
| 1653 |
* Generate all the form builder html and set it in the class |
|---|
| 1654 |
* |
|---|
| 1655 |
* @access public |
|---|
| 1656 |
* @return void |
|---|
| 1657 |
*/ |
|---|
| 1658 |
public function generateHtml() |
|---|
| 1659 |
{ |
|---|
| 1660 |
$html = '<div class="form_builder_wrapper" id="'.$this->getId().'_wrapper">'; |
|---|
| 1661 |
|
|---|
| 1662 |
if( $this->getShowTitle() ) |
|---|
| 1663 |
{ |
|---|
| 1664 |
$html .= $this->getTitleRow(); |
|---|
| 1665 |
} |
|---|
| 1666 |
|
|---|
| 1667 |
$elementsHtml = $this->getElementsHtml(); |
|---|
| 1668 |
|
|---|
| 1669 |
$html .= sfCollapsibleContent::wrapContent($this->getId(), $elementsHtml); |
|---|
| 1670 |
|
|---|
| 1671 |
$html .= '</div>'; |
|---|
| 1672 |
|
|---|
| 1673 |
$this->setHtml($html); |
|---|
| 1674 |
} |
|---|
| 1675 |
|
|---|
| 1676 |
|
|---|
| 1677 |
* Output |
|---|
| 1678 |
* |
|---|
| 1679 |
* Do everything here, and return the output of the form builder |
|---|
| 1680 |
* |
|---|
| 1681 |
* @access public |
|---|
| 1682 |
* @return string |
|---|
| 1683 |
*/ |
|---|
| 1684 |
public function output() |
|---|
| 1685 |
{ |
|---|
| 1686 |
use_helper('Validation'); |
|---|
| 1687 |
|
|---|
| 1688 |
$this->getResponse()->addStylesheet('/sfFormBuilderPlugin/css/form_builder'); |
|---|
| 1689 |
$this->getResponse()->addJavascript('/sfFormBuilderPlugin/js/form_builder'); |
|---|
| 1690 |
$this->getResponse()->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); |
|---|
| 1691 |
|
|---|
| 1692 |
$this->generate(); |
|---|
| 1693 |
|
|---|
| 1694 |
$html = "\n<!--- sfFormBuilder - ".$this->getId()."--->\n\n"; |
|---|
| 1695 |
|
|---|
| 1696 |
$html .= $this->getHtml(); |
|---|
| 1697 |
|
|---|
| 1698 |
if( $this->getRoundCorners() ) |
|---|
| 1699 |
{ |
|---|
| 1700 |
use_helper('Javascript'); |
|---|
| 1701 |
use_helper('nifty'); |
|---|
| 1702 |
|
|---|
| 1703 |
$this->getResponse()->addJavascript('/sfNiftyPlugin/js/niftycube'); |
|---|
| 1704 |
$this->getResponse()->addStylesheet('/sfNiftyPlugin/css/niftyCorners'); |
|---|
| 1705 |
|
|---|
| 1706 |
$html .= javascript_tag("Rounded('div#".$this->getId()."_wrapper','');"); |
|---|
| 1707 |
} |
|---|
| 1708 |
|
|---|
| 1709 |
return $html; |
|---|
| 1710 |
} |
|---|
| 1711 |
|
|---|
| 1712 |
|
|---|
| 1713 |
* __call |
|---|
| 1714 |
* |
|---|
| 1715 |
* @param mixed $method |
|---|
| 1716 |
* @param mixed $arguments |
|---|
| 1717 |
* @access protected |
|---|
| 1718 |
* @return void |
|---|
| 1719 |
*/ |
|---|
| 1720 |
protected function __call($method, $arguments) |
|---|
| 1721 |
{ |
|---|
| 1722 |
if( substr($method, 0, 2) == 'is' ) |
|---|
| 1723 |
{ |
|---|
| 1724 |
$property = substr($method, 2); |
|---|
| 1725 |
$property = strtolower($property[0]).substr($property, 1); |
|---|
| 1726 |
|
|---|
| 1727 |
if( property_exists($this, $property) ) |
|---|
| 1728 |
{ |
|---|
| 1729 |
return $this->$property; |
|---|
| 1730 |
} else { |
|---|
| 1731 |
throw new Exception("$property does not exist on ".get_class($this)); |
|---|
| 1732 |
} |
|---|
| 1733 |
} |
|---|
| 1734 |
else if( substr($method, 0, 3) == 'get' ) |
|---|
| 1735 |
{ |
|---|
| 1736 |
$property = substr($method, 3); |
|---|
| 1737 |
$property = strtolower($property[0]).substr($property, 1); |
|---|
| 1738 |
|
|---|
| 1739 |
if( property_exists($this, $property) ) |
|---|
| 1740 |
{ |
|---|
| 1741 |
return $this->$property; |
|---|
| 1742 |
} else { |
|---|
| 1743 |
throw new Exception("$property does not exist on ".get_class($this)); |
|---|
| 1744 |
} |
|---|
| 1745 |
} |
|---|
| 1746 |
else if( strtolower(substr($method, 0, 3)) == 'set' ) |
|---|
| 1747 |
{ |
|---|
| 1748 |
$property = substr($method, 3); |
|---|
| 1749 |
$property = strtolower($property[0]).substr($property, 1); |
|---|
| 1750 |
|
|---|
| 1751 |
if( property_exists($this, $property) ) |
|---|
| 1752 |
{ |
|---|
| 1753 |
if( array_key_exists(0, $arguments) ) |
|---|
| 1754 |
{ |
|---|
| 1755 |
$this->$property = $arguments[0]; |
|---|
| 1756 |
} else { |
|---|
| 1757 |
$this->$property = NULL; |
|---|
| 1758 |
} |
|---|
| 1759 |
} else { |
|---|
| 1760 |
throw new Exception("$property does not exist on ".get_class($this)); |
|---|
| 1761 |
} |
|---|
| 1762 |
} else { |
|---|
| 1763 |
throw new Exception("$method does not exist on ".get_class($this)); |
|---|
| 1764 |
} |
|---|
| 1765 |
} |
|---|
| 1766 |
} |
|---|
| 1767 |
|
|---|