setDefaults(array( 'lastname' => 'Mamasam', 'code' => '1234', 'num1' => '513', 'num2' => '123', 'num3' => '3456', 'A' => true ) ); $form->addElement('header', '', 'Tests on grouped elements'); // Creates a group of text inputs with templates $id['lastname'] = &HTML_QuickForm::createElement('text', 'lastname', 'Name', array('size' => 30)); $id['code'] = &HTML_QuickForm::createElement('text', 'code', 'Code', array('size' => 5, 'maxlength' => 4)); $form->addGroup($id, 'id', 'ID:', ', ', false); // Add a complex rule for id element $form->addGroupRule('id', array( 'lastname' => array( array('Name is required', 'required', null, 'client'), array('Name is letters only', 'lettersonly', null, 'client') ), 'code' => array( array('Code must be numeric', 'numeric', null, 'client') ) )); // Creates a group of text inputs $areaCode = &HTML_QuickForm::createElement('text', 'num1', null, array('size' => 4, 'maxlength' => 3)); $phoneNo1 = &HTML_QuickForm::createElement('text', 'num2', null, array('size' => 4, 'maxlength' => 3)); $phoneNo2 = &HTML_QuickForm::createElement('text', 'num3', null, array('size' => 5, 'maxlength' => 4)); $form->addGroup(array($areaCode, $phoneNo1, $phoneNo2), 'phoneNo', 'Telephone:', '-', false); // Adds validation rules for groups $form->addGroupRule('phoneNo', 'Please fill all phone fields', 'required', null, 3, 'client'); $form->addGroupRule('phoneNo', 'Values must be numeric', 'numeric', null, 3, 'client'); // Creates a checkboxes group using an array of separators $checkbox[] = &HTML_QuickForm::createElement('checkbox', 'A', null, 'A'); $checkbox[] = &HTML_QuickForm::createElement('checkbox', 'B', null, 'B'); $checkbox[] = &HTML_QuickForm::createElement('checkbox', 'C', null, 'C'); $checkbox[] = &HTML_QuickForm::createElement('checkbox', 'D', null, 'D'); $form->addGroup($checkbox, 'ichkABC', 'ABCD:', array(' ', '
'), false); // At least one element is required $form->addGroupRule('ichkABC', 'Please check at least two boxes', 'required', null, 2, 'client', true); // Validate the radio buttons $form->addRule('iradYesNo', 'Check Yes or No', 'required', null, 'client'); // Creates a standard radio buttons group $radioWithName[] = &HTML_QuickForm::createElement('radio', 'iradYesNoWithName', null, 'Yes', 'Y'); $radioWithName[] = &HTML_QuickForm::createElement('radio', 'iradYesNoWithName', null, 'No', 'N'); $form->addGroup($radioWithName, 'iradYesNoWithName', 'Yes/No with name:', null, false); // Validate the radio buttons $form->addRule('iradYesNoWithName', 'Check Yes or No', 'required', null, 'client'); $form->addElement('text','name' ,array('Name :','More than 4 letters, SVP')); $form->addRule('name', 'Enter a name with at least for letters', 'minlength', 4, 'client'); $form->addElement('text','email' ,'E.mail :'); $form->addElement('text','email_confirmation','Confirm your e.mail :'); $form->addRule('email','Please, enter an email','required',null, 'client', false,true); $form->addRule('email','Please, enter a valid email nom@domaine.com','email',null, 'client'); $form->addRule('email','Please, enter an email with at least 4 characters','minlength',4, 'client'); $form->addRule('email_confirmation','Please, enter a confirmation of your e.mail','required',null, 'client'); $form->addRule('email_confirmation','Please, enter a valid email nom@domaine.com','email',null, 'client'); $form->addRule(array('email_confirmation','email'),'The e.mail confirmation must be the same as your e.mail','compare',null,'client'); $s =& $form->createElement('select','animal','Animal: '); $opts = array('' => 'Choose','dog' => 'woof', 'cat' => 'meow', 'cow' => 'moo'); $s->loadArray($opts,''); $form->addElement($s); $form->addRule('animal', 'Choose an animal', 'required', null, 'client'); $form->addElement('textarea', 'itxaTest', 'Test TextArea:', array('rows' => 3, 'cols' => 20)); $form->addRule('itxaTest', 'SVP saisissez votre texte', 'required', null, 'client'); // Creates a group of buttons to be displayed at the bottom of the form $buttons[] =& $form->createElement('submit', null, 'Submit'); $buttons[] =& $form->createElement('reset', null, 'Reset'); $buttons[] =& $form->createElement('checkbox', 'clientSide', null, 'use client-side validation', array('checked' => 'checked', 'onclick' => "if (this.checked) {this.form.onsubmit = validate_" . $form->getAttribute('id') . ";} else {this.form.onsubmit = null;}")); $form->addGroup($buttons); $form->getValidationScript(); $form->accept($renderer); // Tries to validate the form if ($form->isSubmitted() && $form->validate()) { $data = $form->exportValues(); print_r($data); // do something with $data echo "

Thank you

\n"; } echo $renderer->toHtml(); ?>