apidoc
[ class tree: apidoc ] [ index: apidoc ] [ all elements ]

Class: HTML_QuickForm_SubForm

Source Location: /DB_DataObject_FormBuilder-1.0.2/DB/DataObject/FormBuilder/QuickForm/SubForm.php

Class Overview

HTML_QuickForm_static
   |
   --HTML_QuickForm_SubForm

A few caveats: this element *must* be either created by a call to addElement on your main form (with the


Methods


Child classes:

HTML_QuickForm_SubFormFB
A few caveats: this element *must* be either created by a call to addElement on your main form (with the

Inherited Variables

Inherited Methods


Class Details

[line 106]
A few caveats: this element *must* be either created by a call to addElement on your main form (with the

construction parameters, not an element object) or you must call setParentForm on the element. If you don't, the rules on the subform won't work. Here's the two usages (assuming $form is the main form and $subForm is the sub-form):

require_once('HTML/QuickForm/SubForm.php'); $form->addElement('subForm', 'subFormElementName', 'Sub Form Label', $subForm); //NOTE: with this version $subForm is now a copy in the element so changing // $subForm now will not change the form within the element

OR

require_once('HTML/QuickForm/SubForm.php'); $el =& HTML_QuickForm::createElement('subFormElementName', 'Sub Form Label', $subForm); $el->setParentForm($form); $form->addElement($el);

This also uses a few hacks which access HTML_QuickForm internals which is a no-no, but it's the only way I could get unfreeze and setPersistentFreeze to work as HTML_QuickForm doesn't implement these functions (perhaps these should be added?). This also only works with the default QF renderer, but it shouldn't be too hard to fix it.

This *should* also work for subforms within subforms. ;-)

The following are quick instructions on how to get a dynamic subform working (i.e. a subform which is displayed / hidden by JS and conditionally validated).

Add a hidden field which holds when the sub form is displayed. $form->addElement('hidden', 'subFormDisplayed');

Use this CSS class: .hidden { overflow: hidden; visibility: hidden; display: none; }

Apply that class to a div surrounding the SubForm (I use an altered elementTemplate for QF). You also need a link which calls the javascript below (I've added it to the template for simplicity). Also, only hide it if the sub form was not displayed (if the validation fails you need to redisplay the form).

$renderer =& HTML_QuickForm::defaultRenderer(); $renderer->setElementTemplate(str_replace('{element}', '<a href="javascript:void();" onclick="showSubFormElement()">Show Sub Form</a> <div class="'.($_REQUEST['subFormDisplayed'] ? '' : 'hidden')." id="idForElementDiv">{element}</div>', $renderer->_elementTemplate), 'subFormElement');

Add the JavaScript with the function somewhere in your code.

<script language="javascript" type="text/javascript"> function newCorrectiveAction() { if(document.getElementById("idForElementDiv").className == "hidden") { document.getElementById("idForElementDiv").className = ""; document.getElementById("subFormDisplayed").value = "1"; } else { document.getElementById("idForElementDiv").className = "hidden"; document.getElementById("subFormDisplayed").value = "0"; } } </script>

Now add the sub form element and also make sure to set up the conditional validation. (assuming $subForm is your completed sub form. Note that there may be reference problems here, it's best to have the sub form finished before creating the element).

require_once('HTML/QuickForm/SubForm.php'); function subFormDisplayed($values) { return $values['subFormDisplayed'] == 1; } $el =& HTML_QuickForm::createElement('subForm', 'subFormElement', '', $subForm); $el->setPreValidationCallback('subFormDisplayed');



[ Top ]


Method Detail

HTML_QuickForm_SubForm (Constructor)   [line 112]

HTML_QuickForm_SubForm HTML_QuickForm_SubForm( [ $name = null], [ $label = null], [ $form = null])


Parameters:

   $name   — 
   $label   — 
   $form   — 

[ Top ]

accept   [line 127]

void accept( &$renderer, [ $required = null], [ $error = null])


Parameters:

   &$renderer   — 
   $required   — 
   $error   — 

[ Top ]

checkSubFormRules   [line 197]

void checkSubFormRules( $values)


Parameters:

   $values   — 

[ Top ]

exportValue   [line 176]

void exportValue( &$submitValues, [ $assoc = false])


Parameters:

   &$submitValues   — 
   $assoc   — 

[ Top ]

freeze   [line 154]

void freeze( )


[ Top ]

getName   [line 224]

string getName( )

Gets this element's name
  • Return: name

[ Top ]

onQuickFormEvent   [line 238]

bool onQuickFormEvent( string $event, mixed $arg, object calling &$caller)

Called by HTML_QuickForm whenever form event is made on this element
  • Return: true
  • Access: public

Parameters:

string   $event   —  Name of event
mixed   $arg   —  event arguments
object calling   &$caller   —  object

[ Top ]

setForm   [line 120]

void setForm( &$form)


Parameters:

   &$form   — 

[ Top ]

setName   [line 214]

void setName( string $name)

Sets this element's name

Parameters:

string   $name   —  name

[ Top ]

setParentForm   [line 181]

void setParentForm( &$form)


Parameters:

   &$form   — 

[ Top ]

setPersistantFreeze   [line 168]

void setPersistantFreeze( [ $persistant = false])


Parameters:

   $persistant   — 

[ Top ]

setPreValidationCallback   [line 193]

void setPreValidationCallback( [ $callback = null])

If set, the pre validation callback will be called before the sub-form's validation is checked.

This is meant to allow the developer to turn off sub-form validation for optional forms.


Parameters:

   $callback   — 

[ Top ]

toHtml   [line 138]

string toHtml( )

renders the element
  • Return: the HTML for the element

Overridden in child classes as:

HTML_QuickForm_SubFormFB::toHtml()

[ Top ]

unfreeze   [line 160]

void unfreeze( )


[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:48:18 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.