コード例 #1
0
ファイル: IndexController.php プロジェクト: rakorium/okapi
 /**
  * @param Resources $mvc
  */
 public function formAction(Resources $mvc)
 {
     $flags = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT;
     $request = $mvc('request');
     $escape = $mvc->helper('escape');
     //
     $file = DATA_ROOT . "/form.json";
     $form = new Util\Form($escape);
     $form->load(APPLICATION_ROOT . "/form/contact.yaml");
     $data = file_exists($file) ? json_decode(file_get_contents($file), true) : [];
     $form->hydrate($data);
     if ($request->isMethod('POST')) {
         $form->input($mvc->input('POST'));
         // $form->input(INPUT_POST);
         $data = json_encode($form->extract(), $flags);
         $temp = "{$file}.part";
         file_put_contents($temp, $data);
         rename($temp, $file);
     }
     return ['form' => $form, 'elapsed' => $this->elapsedTime()];
 }
コード例 #2
0
ファイル: OptionList.php プロジェクト: rakorium/okapi
 /**
  * @param string $value
  * @param array $config
  * @return string
  */
 protected function renderCheckbox($value, $config)
 {
     $field = $this->field;
     $type = $field->isMultiple() ? 'checkbox' : 'radio';
     // Render the [checkbox]
     $attributes = ['type' => $type, 'name' => $field->name(), 'value' => $value];
     if ($field->hasValue($value)) {
         $attributes["checked"] = "checked";
     }
     $attr = $field->renderAttributes($attributes);
     $html = "<input{$attr}/>";
     // Render the [label]
     if (isset($config['label'])) {
         $attributes = [];
         foreach ($config as $k => $v) {
             if (Form::isBaseAttribute($k)) {
                 $attributes[$k] = $v;
             }
         }
         if (isset($config['attributes'])) {
             $attributes += $config['attributes'];
         }
         $label = $config['label'];
         $attr = $field->renderAttributes($attributes);
         $html = "<label{$attr}>{$html} <span>{$label}</span></label>";
     }
     return $html;
 }