protected function create_form($uri) { $form = Forms::Form('mainform')->action($uri); $validator = Validation::Validator(); $use_validator = false; foreach ($this->form_fields as $name => $parms) { if (isset($parms['if_component_exists'])) { if (!CMS::component_exists($parms['if_component_exists'])) { continue; } } if (isset($parms['embedded_admin']) && $this->embedded_admin) { if (!$parms['embedded_admin']) { continue; } } $type = isset($parms['type']) ? trim($parms['type']) : 'input'; $method = 'create_form_field_' . $type; if (method_exists($this, $method)) { $this->{$method}($form, $name, $parms); } else { if (isset(self::$field_types[$type])) { self::$field_types[$type]->form_field($form, $name, $parms); if ($dir = self::$field_types[$type]->is_upload($parms)) { $this->upload_fields[$name] = $dir; } } else { $form->input($name); } } if (isset($parms['match'])) { if ($parms['match'] == 'presence') { $validator->validate_presence_of($name, $parms['error_message']); } else { if ($parms['match'] == 'email') { $validator->validate_email_for($name, $parms['error_message']); } else { if ($parms['match'] == 'email presence') { $validator->validate_presence_of($name, $parms['error_message']); $validator->validate_email_for($name, $parms['error_message']); } else { $validator->validate_format_of($name, $parms['match'], $parms['error_message']); } } } $use_validator = true; } } if ($use_validator) { $form->validate_with($validator); } return $form; }
public function create_form($url, $action = 'edit', $from_name = 'mainform') { $form = Forms::Form($from_name)->action($url); $this->filtered_form_fields = $this->filter_form_fields($action); CMS_Fields::form_fields($form, $this->filtered_form_fields); foreach ($this->filtered_form_fields as $name => $parms) { $type = CMS_Fields::type($parms); if ($type->is_upload()) { $this->upload_fields[$name] = $parms; } } $this->form = $form; return $form; }
/** * @param WS_Environment $env */ public function __construct(WS_Environment $env) { $this->env = $env; $this->form = Forms::Form('auth')->method(Net_HTTP::POST)->begin_fields->input('login')->password('password')->end_fields; }
protected function massupdate_form($rows) { if (count($rows) == 0) { return false; } $fields = $this->list_fields(); if ($fields) { foreach ($this->list_fields() as $field => $parms) { if (isset($parms['edit'])) { $data = $parms['edit']; if ($data === true) { $data = array('type' => 'input'); } if (is_string($data)) { $data = array('type' => $data); } $this->massupdate_fields[$field] = $data; } } } if (count($this->massupdate_fields) == 0) { return false; } $form = Forms::Form('massupdate')->action($this->action_url('list', $this->page))->input('ids'); $ids = array(); foreach ($rows as $row) { $id = $this->item_id($row); $ids[$id] = $id; foreach ($this->massupdate_fields as $field => $data) { $name = "{$field}{$id}"; $type = CMS_Fields::type($data); if ($type->is_upload()) { $type = CMS_Fields::type('input'); } $type->form_fields($form, $name, $data); $type->assign_from_object($form, $row->{$field}, $name, $data); } } $form['ids'] = implode(',', $ids); return $form; }