Esempio n. 1
0
 public function testForm()
 {
     $form = new Form();
     $form->action('index.php')->method('post');
     $form->add(['name' => Field::text()->maxlength(50)->required()->label('Your name'), 'email' => Field::email()->label('Your email'), 'telephone' => Field::tel()->label('Telephone number'), 'gender' => Field::choose(['m' => Field::radio()->label('Male'), 'f' => Field::radio()->label('Female')]), 'born' => Field::collection(['day' => Field::number()->min(1)->max(31)->label('Day'), 'month' => Field::number()->min(1)->max(12)->label('Month'), 'year' => Field::number()->min(1900)->max(2013)->label('Year')]), 'language' => Field::select()->options(array('gl' => 'Galician', 'es' => 'Spanish', 'en' => 'English'))->label('Language'), 'friends' => Field::duplicable(['name' => Field::text()->label('Name'), 'email' => Field::email()->label('email'), 'age' => Field::number()->label('Age')]), 'action' => Field::choose(['save' => Field::submit()->html('Save changes'), 'duplicate' => Field::submit()->html('Save as new value')])]);
     $data = array('name' => 'Manuel', 'email' => null, 'telephone' => null, 'gender' => 'm', 'born' => array('day' => 23, 'month' => 12, 'year' => 2013), 'language' => 'gl', 'friends' => array(array('name' => 'Luis', 'email' => '*****@*****.**', 'age' => 30)), 'action' => 'save');
     $form->val($data);
     $this->assertTrue($form->isValid());
     $form->addValidator('myValidator', function ($form) {
         $val = $form['name']->val();
         return empty($val) ? true : 'The name value must be empty';
     });
     $this->assertFalse($form->isValid());
     $this->assertEquals('The name value must be empty', $form->error());
 }
Esempio n. 2
0
 private function createShippingAddress($countries, $i18n)
 {
     return Field::group(['use_shipping_address' => Field::checkbox()->label($i18n->translate('checkoutForm.adr.customShippingAdr'))->render(function ($field) {
         return "<h3><label class='checkbox'>{$field->input} " . $field->label() . '</label></h3>';
     }), 'name' => Field::text()->label($i18n->translate('checkoutForm.adr.name')), 'company' => Field::text()->label($i18n->translate('checkoutForm.adr.company')), 'street' => Field::text()->label($i18n->translate('checkoutForm.adr.street')), 'zip' => Field::text()->label($i18n->translate('checkoutForm.adr.zip')), 'city' => Field::text()->label($i18n->translate('checkoutForm.adr.city')), 'country' => Field::select()->options($countries)->label($i18n->translate('checkoutForm.adr.country'))])->render(function ($group) {
         return '<div class="adrGroup">' . $group->childrenToHtml() . '</div>';
     });
 }