Exemple #1
0
 public function setMethod($method)
 {
     $method = strtoupper($method);
     if ($this->has(self::_METHOD)) {
         $this->get(self::_METHOD)->setAttribute('value', $method);
     } else {
         $element = new Hidden(self::_METHOD);
         $element->setAttribute('value', $method);
         $this->add($element);
     }
     $this->setAttribute('data-method', $method);
     if ($this->isValidMethod($method)) {
         $this->_method = $method;
     }
     return $this;
 }
 /**
  * Initialize the products form
  */
 public function initialize($entity = null, $options = array())
 {
     if (isset($options['edit'])) {
         $item = new Hidden("id");
         $item->setAttribute('class', 'dynamicId');
         $this->add($item);
     }
     $attr = new $options['referencia']();
     foreach ($attr->rules() as $key => $value) {
         if ($value['type'] == 'select') {
             $item = new Select($key, $value['referencia']::find(), array('using' => array('_id', 'nome')));
         } else {
             if ($value['type'] == 'hidden') {
                 $item = new Hidden($key);
             } else {
                 if ($value['type'] == 'textarea') {
                     $item = new TextArea($key);
                 } else {
                     if ($value['type'] == 'number') {
                         $item = new Numeric($key);
                     } else {
                         if ($value['type'] == 'file') {
                             $item = new File($key);
                         } else {
                             $item = new Text($key);
                         }
                     }
                 }
             }
         }
         $item->setAttribute('class', 'form-control');
         if (!$value['type'] == 'file') {
             $item->setAttribute('required', 'true');
         }
         if (!isset($value['primary']) && !isset($value['hide'])) {
             $this->add($item);
         }
     }
 }
Exemple #3
0
 public function initialize($entity = null, $options = null)
 {
     // Make
     $make = new Text("make");
     $make->setLabel('Make');
     $make->addValidators(array(new PresenceOf(array('message' => 'Enter your car make'))));
     $this->add($make);
     // Model
     $model = new Text("model");
     $model->setLabel('Model');
     $model->addValidators(array(new PresenceOf(array('message' => 'Enter your car model'))));
     $this->add($model);
     // Year
     $year_options = array();
     for ($i = date('Y'); $i > date('Y') - 100; $i--) {
         $years[$i] = $i;
     }
     $year = new Select("year", $years);
     $year->setLabel('Year');
     $year->addValidators(array(new PresenceOf(array('message' => 'Select the year your car was registered'))));
     $this->add($year);
     //Colour
     $colour = new Text("colour");
     $colour->setLabel('Colour');
     $colour->addValidators(array(new PresenceOf(array('message' => 'Choose a colour'))));
     $this->add($colour);
     // Mileage
     $mileage = new Text("mileage");
     $mileage->setLabel('Mileage (miles)');
     $mileage->addValidators(array(new PresenceOf(array('message' => 'Enter your car\'s current mileage'))));
     $this->add($mileage);
     // Fuel
     $fuel = new Text("fuel");
     $fuel->setLabel('Fuel');
     $fuel->addValidators(array(new PresenceOf(array('message' => 'Tell us which fuel your car runs on'))));
     $this->add($fuel);
     // Engine Size
     $engine_cc = new Text("engine_cc");
     $engine_cc->setLabel('Engine size (cc)');
     $engine_cc->addValidators(array(new PresenceOf(array('message' => 'Tell us how many CC your engine is'))));
     $this->add($engine_cc);
     // Price
     $price = new Text("price");
     $price->setLabel('Price (GBP)');
     $price->addValidators(array(new PresenceOf(array('message' => 'Please enter a sale price'))));
     $this->add($price);
     // Postcode
     $postcode = new Text("postcode");
     $postcode->setLabel('Postcode');
     $postcode->addValidators(array(new PresenceOf(array('message' => 'Where is your car located?'))));
     $this->add($postcode);
     // ID
     $ID = new Hidden("ID");
     $ID->setAttribute("value", "");
     $this->add($ID);
     // Lat
     $lat = new Hidden("lat");
     $lat->setAttribute("value", "0");
     $this->add($lat);
     // Lng
     $lng = new Hidden("lng");
     $lng->setAttribute("value", "0");
     $this->add($lng);
 }