Hooray, the form validated! This is what it returned:
' .''.print_r($valueSet, true).'' .($valueSet->imgsave ? '
image-submit click-coordinates:
'.print_r($testForm->getElementByName('imgsave')->getCoords(), true).'' : '') .'
addCssClasses('testform')
->showMessages('Errors:')
//->showCustomMessages('Errors:')
->setLanguage('english')
->useExternalFormDeclaration()
->setPackagePath('/////htmlform///')
->setEnctype('multipart/form-data')
->useReducedErrorMarking()
;
//--|FIRST-FIELDSET----------
/**
* Create a fieldset.
* - apply a legend to it
*/
$testFieldSet = FieldSet::get()->setLegend('simple widgets');
/**
* Create a custom-html-content-element and add it to the fieldset (simple, wrapped, all-purpose html)
*/
$testFieldSet->addElement(
CustomHtml::get()
->setHtml('')
);
/**
* Create a standard text input and add it to the fieldset.
* - add a label
* - set a default text
* - add random bordered css-class
* - set width/size
* - set the max input chars
* - set a validator (has to be an eMail-address, has to fulfill random expression)
* - refill from default refiller (get/post)
*/
$testFieldSet->addElement(
InputText::get('testinputtext')
->setLabel('standard text input (must be valid eMail-address):')
->setText('me@you.com')
->setCssClasses('bordered')
->setSize(25)
->setMaxLength(10)
->setValidator(
FormValidator::get()
->setEmail()
->setCustomCase(true)
)
->refill()
);
/**
* Create a standard single select and add it to the fieldset.
* - add a label
* - add options to choose from (optgroup => [value => text])
* - select a entry by text as default
* - set a validator (must be a simple digit-number, has custom error message)
* - refill from default refiller (get/post)
*/
$testFieldSet->addElement(
Select::get('testselectsingle')
->setLabel('single select (must select number):')
->setOptions(
array(
'strings' => array(
'a' => 'test1', 'b' => 'test2'
),
'numbers' => array(
'3' => '333'), 'c' => '444.4'
)
)
->setSelectedSingle('333')
->setValidator(
FormValidator::get()
->setDigits()
->setErrorMessage('Please choose a "only digit"-value.')
)
->refill()
);
/**
* Create a single select with a "none"-default and add it to the fieldset.
* - add a label
* - set options (value => text)
* - set validator (must have a selection)
* - refill from default refiller (get/post)
*/
$testFieldSet->addElement(
Select::get('testselectsinglemixed')
->setLabel('single select (must have a selection)')
->setOptions(array('' => '---', 'b' => 'hey', 'c' => 'you'))
->setValidator(
FormValidator::get()
->setRequired()
)
->refill()
);
/**
* Create a multiple select and add it to the fieldset.
* - add label
* - set as multiple select
* - set options (value => text)
* - set css classes for options (they cycle if less then number of options)
* - set titles for options (not quite standard, but practical, they also cycle)
* - set several options selected as default by index starting with 1
* - set select height
* - set validator (must have selection, values of options must be "a" or "c", set all standard messages as custom here)
* - refill from default refiller (get/post)
*/
$testFieldSet->addElement(
Select::get('testselectmultiple')
->setLabel('multi select (must have selection, values must be "a" or "c"):')
->setMultiple()
->setOptions(array('a' => 'test1', 'b' => 'test2', 'c' => 'test3'))
->setOptionCssClasses(array('odd', 'even'))
->setOptionTitles(array('eins', 'zwei'))
->setSelectedIndices(array(1, 3))
->setSize(3)
->setValidator(
FormValidator::get()
->setRequired()
->setCharacterClass('ac')
->setAutoErrorMessagesAsCustom()
)
->refill()
);
/**
* Create a standard text input and add it to the fieldset.
* - add a label
* - set valid standard date as default value
* - set validator (must be standard date if filled, but is optional)
* - refill from default refiller (get/post)
*/
$testFieldSet->addElement(
InputText::get('datetest')
->setLabel('standard text input (must be a standard date, is optional):')
->setText('1/12/2002')
->setValidator(
FormValidator::get()
->setDate()
->setOptional()
)
->refill()
);
/**
* Create a standard text input and add it to the fieldset.
* - add a label
* - set a valid iso-date as default text
* - set validator (must be iso-date)
* - refill from default refiller (get/post)
*/
$testFieldSet->addElement(
InputText::get('dateisotest')
->setLabel('standard text input (must be an iso-date):')
->setText('2002-12-1')
->setValidator(
FormValidator::get()
->setDateISO()
)
->refill()
);
/**
* Create a standard text input and add it to the fieldset.
* - add a label
* - set a valid german date as default text
* - set validator (must be german date)
* - refill from default refiller (get/post)
*/
$testFieldSet->addElement(
InputText::get('datedetest')
->setLabel('standard text input (must be german date)')
->setText('1.12.2002')
->setValidator(
FormValidator::get()
->setDateDE()
)
->refill()
);
/**
* Create a standard text input and add it to the fieldset.
* - add a label
* - set a valid english decimal number as default text
* - set validator (must be english decimal number)
* - refill from default refiller (get/post)
*/
$testFieldSet->addElement(
InputText::get('numbertest')
->setLabel('standard text input (must be english decimal number):')
->setText('100.1')
->setValidator(
FormValidator::get()
->setNumber()
)
->refill()
);
/**
* Create a standard text input and add it to the fieldset.
* - add a label
* - set a valid german decimal number as default text
* - set validator (must be german decimal number)
* - refill from default refiller (get/post)
*/
$testFieldSet->addElement(
InputText::get('numberdetest')
->setLabel('standard text input (must be german decimal number):')
->setText('100,1')
->setValidator(
FormValidator::get()
->setNumberDE()
)
->refill()
);
/**
* Create a password text input and add it to the fieldset.
* - add a label
* - set a default text
* - set max char number to 8
* - refill from default refiller (get/post)
*/
$testFieldSet->addElement(
InputPassword::get('pass1')
->setLabel('password text input:')
->setText('testtest')
->setMaxLength(8)
->refill()
);
/**
* Create a file input and add it to the fieldset.
* - add a label
* - set a default text (to show that it doesn't show)
* - set accept (will not be used by browsers, but could be used for internal checks)
* - refill from default refiller (get/post)
*/
$testFieldSet->addElement(
InputFile::get('file1')
->setLabel('file input:')
->setText('no file selected')
->setAccept('text/*')
);
/**
* Add the fieldset to the form (cell 1)
*/
$testForm->addElement($testFieldSet);
/**
* Create an align block to insert buttons into the form, but being aligned right instead of left.
*/
$testAlignBlock = AlignBlock::get();
/**
* Add input submit to align block.
* - set button caption
*/
$testAlignBlock->addElement(
InputSubmit::get('save', 'save')
->setCaption('submit')
);
/**
* Add alternative image-submit to align block.
* - set image-url
* - coords of clicks are shown down below in the result-display of the form
*/
$testAlignBlock->addElement(
InputImage::get('imgsave', 'imgsave')
->setSrc('img/submit.png')
);
/**
* Add reset-button to align block.
* - set button caption
*/
$testAlignBlock->addElement(
InputReset::get('reset', 'reset')
->setCaption('reset')
);
/**
* Add input button to align block.
* - set button caption
* - set the button disabled
*/
$testAlignBlock->addElement(
InputButton::get('btn1', 'btn1')
->setCaption('random button')
->setDisabled()
);
/**
* Insert align block directly into the form, beneath the fieldset.
*/
$testForm->addElement($testAlignBlock);
/**
* Add a second cell to the form.
*/
$testForm->addCell();
//--|SECOND-FIELDSET----------
/**
* Create a second fieldset.
* - set legend
*/
$testFieldSet2 = FieldSet::get()->setLegend('extended widgets');
/**
* Create standard text input and add it to second fieldset.
* - add a label
* - set valid default text (10 length)
* - set widget title
* - set validator (must be filled, must have min 3 chars, must hav max 10 chars, only letters and umlauts)
* - refill from default refiller (get/post)
*/
$testFieldSet2->addElement(
InputText::get('testtextinput2')
->setLabel('standard text input (text length between 3 and 10):')
->setText('lolcatpaws')
->setTitle('between 3 and 10 please')
->setValidator(
FormValidator::get()
->setRequired()
->setMinLength(3)
->setMaxLength(10)
->setCharacterClass('a-zA-ZäöüÄÖÜß')
)
->refill()
);
/**
* Create standard text input and add it to second fieldset.
* - add a label
* - set valid default text (5 length)
* - set validator (must have between 4 and 6 chars)
* - refill from default refiller (get/post)
*/
$testFieldSet2->addElement(
InputText::get('testtextinput3')
->setLabel('standard text input (text length between 4 and 6):')
->setText('tenso')
->setValidator(
FormValidator::get()
->setRangeLength(array(4,6))
)
->refill()
);
/**
* Create standard text input and add it to second fieldset.
* - add a label
* - set valid default text
* - set validator (value must be min 3, value must be max 10)
* - refill from default refiller (get/post)
*/
$testFieldSet2->addElement(
InputText::get('testtextinput5')
->setLabel('standard text input (value between 3 and 10):')
->setText('4')
->setValidator(
FormValidator::get()
->setMin(3)
->setMax(10)
)
->refill()
);
/**
* Create standard text input and add it to second fieldset.
* - add a label
* - set valid default text
* - set validator (value must be between 4 and 6)
* - refill from default refiller (get/post)
*/
$testFieldSet2->addElement(
InputText::get('testtextinput6')
->setLabel('standard text input (value between 4 and 6):')
->setText('5')
->setValidator(
FormValidator::get()
->setRange(array(4, 6))
)
->refill()
);
/**
* Create standard text input and add it to second fieldset.
* - add a label
* - add random bordered css-class
* - set valid default text (absolute url)
* - set validator (value must be a valid url)
* - refill from default refiller (get/post)
*/
$testFieldSet2->addElement(
InputText::get('testtextinput4')
->setLabel('standard text input (must be url):')
->addCssClasses('bordered')
->setText('http://www.google.com')
->setValidator(
FormValidator::get()
->setUrl()
)
->refill()
);
/**
* Create a radiogroup and add it to second fieldset.
* - add a label
* - set selectable options (value => labeltext)
* - set default selection
* - set width of radiogroup (amount of radiobutton-cols)
* - refill from default refiller (get/post)
*/
$testFieldSet2->addElement(
InputRadio::get('radios1')
->setLabel('radiogroup:')
->setOptions(array('a' => 'radio1', 'b' => 'radio2', 'c' => 'radio3', 'd' => 'radio4'))
->setOptionCssClasses(array('allthesame'))
->setOptionTitles(array('one', 'two', 'three', 'four'))
->setSelectedValue('d')
->setWidth(3)
->refill()
);
/**
* Create a checkboxgroup and add it to second fieldset (not instantly here).
* - add a label
* - set random css-class to prove that it isn't rendered (makes no sense for composita)
* - set selectable options (value => labeltext)
* - set css-classes for options (cycle if number smaller than option count)
* - set default selection
*/
$checkbox1 = InputCheckbox::get('check1')
->setLabel('checkboxgroup:')
->setCssClasses('nothing')
->setOptions(array('a' => 'check1', 'b' => 'check2', 'c' => 'check3', 'd' => 'check4'))
->setOptionCssClasses(array('odd', 'equal', 'even'))
->setOptionTitles(array('just one for all'))
->setSelected(array('check2', 'check3'))
;
$testFieldSet2->addElement($checkbox1);
/**
* Create a datetime text input and add it to second fieldset.
* - add a label
* - set a valid date text value
* - set text readonly, to prevent direct editing
* - set widget up for german dates
* - set time format to am/pm-notation
* - set navigation by arrows
* - set up time display
* - set config-values for javascript(3 chars for weekdays, color for sundays, color for saturdays, color for weekdays)
* - set validator (must be german date)
* - refill from default refiller (get/post)
*/
$testFieldSet2->addElement(
JsDateTime::get('cal1', 'cal1')
->setLabel('datetime (german date):')
->setText('12.12.2008')
->setReadonly()
->setUpAsGermanDate()
->setAmPmTime()
->setArrowSelection()
->showTime()
->setJsConfigVars(
array(
'SpanBorderColor' => '#37c900',
'CalBgColor' => '#444444',
'WeekChar' => 3,
'SundayColor' => '#333333',
'SaturdayColor' => '#333333',
'WeekDayColor' => '#444444',
'TodayColor' => '#666666',
'SelDateColor' => '#37c900',
'YrSelColor' => '#ffffff'
)
)
->setValidator(
FormValidator::get()
->setDateDE()
)
->refill()
);
/**
* Create textarea and add it to the second fieldset.
* - add a label
* - add a random javascript-event-handler
* - add a valid text
* - set dimensions of textarea (20 cols, 10 rows)
* - set validator (custom case, with message result, empty string represents true here)
* - refill from default refiller (get/post)
*/
$testFieldSet2->addElement(
TextArea::get('textarea1')
->setLabel('textarea (only normal chars, umlauts and punctuation):')
->setJsEventHandler('onclick', 'alert(\'onclick-test\');')
->setText('Hello world!')
->setSize(20, 10)
->setValidator(
FormValidator::get()
->setCustomCase(
preg_match('/^[a-zA-ZäöüÄÖÜß!.,? ]+$/u', isset($_REQUEST['textarea1']) ? $_REQUEST['textarea1'] : 'Hallo Welt!')
? ''
: 'Keinen Murks in den Fließtext ey!'
)
)
->refill()
);
/**
* Add second fieldset to second cell of the form.
*/
$testForm->addElement($testFieldSet2, 2);
/**
* Create a custom html-content a append it in the middle of the form after a specific widget.
*/
$testForm->insertElementAfter('testselectmultiple',
CustomHtml::get()
->setHtml(
'
' .'This piece was injected into the middle of the form after completely building it.' .'
' ) ); /** * Set a headline and an explanation for the form. */ $testForm->setHeadline('HtmlForm Testcase Scenario'); $testForm->setExplanation( 'Use this form to test out the possibilities and see what else is possible. Feel free to break it...'.print_r($valueSet, true).'' .($valueSet->imgsave ? '
'.print_r($testForm->getElementByName('imgsave')->getCoords(), true).'' : '') .'