function getInput($attr = array()) { $this->template->trySet('field_caption', ''); $this->template->tryDel('label_container'); $label = ' <label for="' . $this->name . '">' . $this->caption . '</label>'; return parent::getInput(array_merge(array('type' => 'checkbox', 'value' => '1', 'checked' => (bool) ($this->true_value == $this->value)), $attr)) . $label; }
public function __construct(array $field = array()) { parent::__construct($field); $this->_model = Arr::get($field, 'model', $this->_model); $this->_rows = ORM::factory($this->_model)->find_all(); $this->_name_column = Arr::get($field, 'name_column', $this->_name_column); }
function getInput() { $s = $this->name . '_slider'; $this->js(true)->_selector('#' . $s)->slider(array('min' => $this->min, 'max' => $this->max, 'value' => $this->js()->val(), 'change' => $this->js()->_enclose()->val($this->js()->_selector('#' . $s)->slider('value'))->change())); $this->setProperty('style', 'display: none'); return '<table width=200 border=0><tr>' . '<td align="left">' . $this->left . '</td>' . '<td align="right">' . $this->right . '</td>' . '</tr><tr><td colspan=2>' . parent::getInput() . '<div id="' . $s . '"></div></td></tr></table>'; }
/** * Create button element * @param string $type * @param string $title */ public function newButton($type, $value) { $e = $this->buttons->newElement('ButtonInput', $type); $e->setValue($value); $e->setDefaultValue($value); $e->setType($type); return $e; }
protected function input_fields() { $fields = parent::input_fields(); if ($fields['value']) { $fields['value'] = date('Y-m-d H:i:s', $fields['value']); } return $fields; }
/** * Initialization. */ public function init() { parent::init(); // template fixes $this->addClass('atk-form atk-form-stacked atk-form-compact atk-move-right'); $this->template->trySet('fieldset', 'atk-row'); $this->template->tryDel('button_row'); $this->addClass('atk-col-3'); // add field $this->search_field = $this->addField('Line', 'q', '')->setAttr('placeholder', 'Search')->setNoSave(); // cancel button if ($this->show_cancel && $this->recall($this->search_field->short_name)) { $this->add('View', null, 'cancel_button')->setClass('atk-cell')->add('HtmlElement')->setElement('A')->setAttr('href', 'javascript:void(0)')->setClass('atk-button')->setHtml('<span class="icon-cancel atk-swatch-red"></span>')->js('click', array($this->search_field->js()->val(null), $this->js()->submit())); } /** @type HtmlElement $b Search button */ $b = $this->add('HtmlElement', null, 'form_buttons'); $b->setElement('A')->setAttr('href', 'javascript:void(0)')->setClass('atk-button')->setHtml('<span class="icon-search"></span>')->js('click', $this->js()->submit()); }
protected function input_fields() { $fields = parent::input_fields(); foreach ($this->_fields as $name => $field) { $this->_fields[$name]->set_attribute('class', $fields['name'] . '_add_element'); } $fields['value'] = unserialize($fields['value']); $fields['validate'] = $this->_validate; $fields['labels'] = $this->_labels; $fields['fields'] = $this->_fields; return $fields; }
function getInput($attr = array()) { $this->template->trySet('field_caption', ''); $this->template->tryDel('label_container'); if (strpos('<', $this->caption) !== false) { // HTML in label $label = $this->caption; } else { $label = '<label for="' . $this->name . '">' . $this->caption . '</label>'; } return parent::getInput(array_merge(array('type' => 'checkbox', 'value' => '1', 'checked' => (bool) ($this->true_value == $this->value)), $attr)) . $label; }
function t_formfield($field) { switch ($field['type']) { case Form_Field::CHECKBOX: return '<input type="checkbox" ' . 'value="1" ' . 'name="' . $field['name'] . '" ' . ($_REQUEST[$field['name']] ? ' checked="checked"' : '') . $field['tag_attributes'] . ' />'; case Form_Field::SELECT: return '<select name="' . $field['name'] . '" ' . $field['tag_attributes'] . '>' . Form_Field::OptionsSimple($field['options'], $_REQUEST[$field['name']]) . '</select>'; case Form_Field::TEXT: return '<input type="text" ' . 'name="' . $field['name'] . '" ' . 'value="' . htmlspecialchars($_REQUEST[$field['name']], ENT_QUOTES) . '" ' . $field['tag_attributes'] . ' />'; case Form_Field::TEXTAREA: return '<textarea name="' . $field['name'] . '" ' . $field['tag_attributes'] . '>' . htmlspecialchars($_REQUEST[$field['name']]) . '</textarea>'; } }
protected function __construct(ORM $object, array $fields = array()) { $this->_object = $object; $this->set_name($object->object_name()); $hash = ''; foreach ($fields as $name => $field) { if (!is_array($field)) { $field = array('type' => $field); } $field_cfg = array('name' => $name, 'label' => Arr::get($object->labels(), $name), 'value' => $object[$name]); $field = Arr::merge($field_cfg, (array) $field); $field = Form_Field::factory($field); $field->set_object($object); $this[$name] = $field; $hash .= $field->hash(); } $this->_hash = md5($hash); }
/** * Add a field using one of many syntaxes * Returns reference to the field */ public function field($label, $callback = null) { if (is_a($callback, 'Squi\\Form_Field')) { $field = $callback; } elseif (is_a($label, 'Squi\\Form_Field')) { $field = $label; } else { $field = Form_Field::make(); } $field->form = $this; // field('field_name') if (is_null($callback) && is_string($label)) { $field->name = $label; // Automagic label by capitalization $field->label($label, $humanize = true); } elseif (is_null($callback) && is_callable($label)) { call_user_func($label, $field, $this); } elseif (is_null($callback) && is_array($label)) { if (isset($label[0]) && isset($label[1])) { $field = $label[1]; $field->label($label[0]); } else { $field->parse_config($label); } } elseif (is_string($label) && is_array($callback)) { $field->label($label); // The array could either be an array of Table_Fields // or an assoc array defining a field if (is_a(reset($callback), 'Squi\\Form_Field')) { $field->fields = $callback; } else { $field->parse_config($callback); } } elseif (is_a($label, 'Squi\\Form_Label')) { $field->label($label); } elseif (is_string($label) && is_string($callback)) { $field->label($label); $field->name = $callback; } $this->fields[] = $field; return $field; }
function loadPOST() { parent::loadPOST(); if (isset($_FILES[$this->name . '_f'])) { $f = $_FILES[$this->name . '_f']; // Uploading something! if ($f['error']) { $this->uploadFailed('Error: ' . $f['error']); } if ($this->model) { $model = $this->model; $model->set('filestore_volume_id', $model->getAvailableVolumeID()); $model->set('original_filename', $this->getFilePath()); $model->set('filestore_type_id', $model->getFiletypeID($this->getOriginalType())); $model->import($this->getFilePath()); $model->save(); $this->hook('uploaded', array($model)); $this->uploadComplete($this->model->id, $this->model->get()); } } $this->uploadFailed('You should set model for this field'); }
function validate() { //empty value is ok if ($this->value == '') { return parent::validate(); } //checking if there are exactly 2 separators if (substr_count($this->value, $this->sep) != 2) { $this->invalid(); } else { $c = explode($this->sep, $this->value); //year should be first, month should be second and a day should be last if (strlen($c[0]) != 4 || $c[1] <= 0 || $c[1] > 12 || $c[2] <= 0 || $c[2] > 31) { $this->invalid(); } //now attempting to convert to date if (strtotime($this->value) === false) { $this->invalid(); } else { $this->set($this->value); } } return parent::validate(); }
<label>Upload .jpg Image:</label> <span class="field-container"><input type="file" size="60" name="thumb_uploads[]" /></span> <img src="images/add-16x16.png" class="clickable vertical-middle" style="padding-left: 6px;" title="Add" /> <img src="images/remove-16x16.png" class="clickable vertical-middle" style="padding-left: 6px;" title="Remove" /> </div> </div> <?php } ?> <div class="fieldset"> <div class="legend">Custom Fields</div> <?php echo Form_Field::GenerateFromCustom('video'); ?> </div> <?php } //if( empty($categories) ): ?> </div> </div> <div id="dialog-buttons"> <img src="images/activity-16x16.gif" height="16" width="16" border="0" title="Working..." /> <?php if (!empty($categories)) {
function getInput($attr = array()) { return parent::getInput(array_merge(array('type' => 'checkbox', 'value' => 'Y', 'checked' => $this->value == 'Y'), $attr)); }
function setModel($m) { $ret = parent::setModel($m); $this->setValueList(array('foo', 'bar')); return $ret; }
<div class="field"> <label>2257 URL:</label> <span class="field-container"><input type="text" size="60" name="us2257_url" value="<?php echo Request::Get('us2257_url'); ?> " /></span> </div> </div> <div class="fieldset"> <div class="legend">Custom Fields</div> <?php echo Form_Field::GenerateFromCustom('sponsor'); ?> </div> </div> </div> <div id="dialog-buttons"> <img src="images/activity-16x16.gif" height="16" width="16" border="0" title="Working..." /> <input type="submit" id="button-save" value="<?php echo isset($editing) ? 'Save Changes' : 'Add Sponsor'; ?> " /> <input type="button" id="dialog-button-cancel" value="Cancel" style="margin-left: 10px;" /> </div>
<div class="field"> <label>Name:</label> <span class="field-container"><input type="text" size="40" name="name" value="<?php echo Request::Get('name'); ?> " /></span> </div> <div class="field"> <label>Account Type:</label> <span class="field-container"> <select name="type" id="account_type"> <?php $opts = array('Superuser', 'Editor'); echo Form_Field::OptionsSimple($opts, Request::Get('type')); ?> </select> </span> </div> </div> <div class="fieldset"> <div class="legend">Privileges</div> <div class="overlay" id="privileges_overlay">PRIVILEGES ARE ONLY SET FOR EDITOR ACCOUNTS</div> <table width="700" align="center" id="privileges_checkboxes"> <tr>
public function getInput($attr = array()) { return parent::getInput(array_merge(array('type' => 'search'), $attr)); }
public function get_cleaned_value($value) { $value = trim($value); return parent::get_cleaned_value($value); }
function getInput($attr = array()) { return parent::getInput(array_merge(array('' => 'textarea'), $attr)) . $this->app->encodeHtmlChars($this->value) . $this->getTag('/textarea'); }
/** * Normalize POSTed data * * @return void */ function normalize() { $data = $this->get(); if (is_array($data)) { $data = join($this->separator, $data); } $data = trim($data, $this->separator); if (get_magic_quotes_gpc()) { $this->set(stripslashes($data)); } else { $this->set($data); } return parent::normalize(); }
<div id="dialog-panel"> <div style="padding: 8px;"> <div id="dialog-help"> <a href="docs/cp-banner.html" target="_blank"><img src="images/help-22x22.png" alt="Help" title="Help" border="0" /></a> </div> <div class="field"> <label>Sponsor:</label> <span class="field-container"> <select name="sponsor_id"> <option value="">-- None --</option> <?php $DB = GetDB(); $sponsors = $DB->FetchAll('SELECT `sponsor_id`,`name` FROM `tbx_sponsor` ORDER BY `name`'); echo Form_Field::Options($sponsors, Request::Get('sponsor_id'), 'sponsor_id', 'name'); ?> </select> </span> </div> <div class="field"> <label>Zone:</label> <span class="field-container"><input type="text" size="40" name="zone" value="<?php echo Request::Get('zone'); ?> " acomplete="tbx_banner.zone" /></span> </div> <div class="field"> <label>Tags:</label>
/** * @param Form_Field $field * * @return Form_Processor */ public function addField(Form_Field $field) { $name = $field->getName(); $initalValue = Arr::get($this->initalValues, $name); $value = $this->requestMethod === Request::GET ? $this->request->query($name) : $this->request->post($name); //if (is_string($value) && !strlen($value)) $value = NULL; if ($this->isInitial() && NULL === $value) { $value = $field->isSetInitialValue() ? $field->getInitialValue() : $initalValue; } $this->fields[$name] = $field->setDefaults($this->fieldDefaults)->setInitialValue($initalValue, FALSE)->setValue($value); if ($field->getType() == Form_Field::FILE) { $this->setEncType('multipart/form-data'); } return $this; }
<input type="hidden" name="r" value="<?php echo isset($editing) ? 'tbxGenericEdit' : 'tbxGenericAdd'; ?> (video-custom-field)" /> <input type="hidden" name="field_id" value="<?php echo Request::Get('field_id'); ?> " /> </form> <div id="validator-master" style="margin: 3px 0; display: none;"> <select name="validator[type][]"> <?php $reflect = new ReflectionClass('Validator_Type'); echo Form_Field::Options(array_flip($reflect->getConstants())); ?> </select> <input type="text" name="validator[message][]" size="40" defaultvalue="Error message" class="defaultvalue" value="Error message" /> <input type="text" name="validator[extras][]" size="10" defaultvalue="Extras" class="defaultvalue" value="Extras" /> <img src="images/add-16x16.png" class="clickable vertical-middle" style="padding-left: 6px;" title="Add" /> <img src="images/remove-16x16.png" class="clickable vertical-middle" style="padding-left: 6px;" title="Remove" /> </div> <?php IncludeJavascript(BASE_DIR . '/admin/js/cp-custom-field-add.js'); ?> <?php if (isset($editing)) { ?>
public function getInput() { if ($id = $_GET[$this->name . '_delete_action']) { // this won't be called in post unfortunatelly, because ajaxec does not send POST data // This is JavaScript upload. We do not want to trigger form submission event if ($c = $this->model) { try { $c->tryLoad($id); $c->delete(); $this->js()->_selector('[name=' . $this->name . ']')->atk4_uploader('removeFiles', array($id))->execute(); } catch (BaseException $e) { $this->js()->univ()->alert('Could not delete image - ' . $e->getMessage())->execute(); } //$this->js(true,$this->js()->_selector('#'.$this->name.'_token')->val('')) // ->_selectorRegion()->closest('tr')->remove()->execute(); } } if ($id = $_GET[$this->name . '_save_action']) { // this won't be called in post unfortunatelly, because ajaxec does not send POST data // This is JavaScript upload. We do not want to trigger form submission event if ($c = $this->model) { $c->tryLoad($id); $f = $c; $mime = $f->ref($this->getTypeIDFieldName())->get('mime_type'); $path = $f->getPath(); $name = $f->get($this->getOriginalFilenameFieldName()); $len = $f->get($this->getFilesizeFieldName()); header("Content-type: {$mime}"); header("Content-legnth: {$len}"); if ($_GET['redirect']) { /* it should be possible to use redirect method as well */ header('HTTP/1.1 301 Moved Permanently'); header("Location: {$path}"); } else { if (!$_GET['view']) { header("Content-disposition: attachment; filename=\"{$name}\""); } echo file_get_contents($path); } exit; /* unreachable code $this->js()->_selector('[name='.$this->name.']')->atk4_uploader('removeFiles', array($id))->execute(); */ //$this->js(true,$this->js()->_selector('#'.$this->name.'_token')->val('')) // ->_selectorRegion()->closest('tr')->remove()->execute(); } } if ($_GET[$this->name . '_upload_action'] && !$_POST) { if (!$this->model) { $this->uploadFailed('You are not using model with upolad field. ' . 'Please use "isUploaded" and uploadComplete() methods in form submit handler'); } $this->uploadFailed('Webserver settings have blocked this file. Perhaps post_max_size should incleased (' . $_SERVER['CONTENT_LENGTH'] . ' sent, ' . ini_get('post_max_size') . ' max)(post: ' . json_encode($_POST) . ', get: ' . json_encode($_GET) . ')'); } $o = ''; $options = array('size_limit' => $this->max_file_size); switch ($this->mode) { case 'simple': break; case 'iframe': $options['iframe'] = $this->name . '_iframe'; break; case 'flash': $options['flash'] = true; break; } if (is_numeric($this->multiple)) { $options['multiple'] = $this->multiple; } if ($this->mode != 'simple') { $options['form'] = $this->owner; $this->js(true)->_load('ui.atk4_uploader')->atk4_uploader($options); } // First - output list of files wi already have uploaded $o .= '<div id="' . $this->name . '_files" class="uploaded_files">' . $this->getUploadedFiles() . '</div>'; $o .= $this->getTag('input', array('type' => 'hidden', 'name' => 'MAX_FILE_SIZE', 'value' => $this->max_file_size)); $o .= $this->getTag('input', array('type' => 'hidden', 'name' => $this->name . '_token', 'value' => $this->value, 'id' => $this->name . '_token')); $o .= parent::getInput(); return $o; }
function getInput($attr = array()) { return parent::getInput(array_merge(array('type' => 'hidden'), $attr)); }
</div> <form method="post" action="ajax.php"> <div id="dialog-panel"> <div style="padding: 8px;"> <div class="field"> <label class="short">Templates:</label> <span class="field-container"> <?php $templates = Dir::ReadFiles(TEMPLATES_DIR, '~^email~'); asort($templates); ?> <select name="templates[]" id="templates" multiple="multiple" size="10"> <?php echo Form_Field::OptionsSimple($templates); ?> </select> </span> </div> <div class="field"> <label class="short">Search For:</label> <span class="field-container"><textarea name="search" id="search" rows="5" cols="110"></textarea></span> </div> <div class="field"> <label class="short">Replace With:</label> <span class="field-container"><textarea name="replace" id="replace" rows="5" cols="110"></textarea></span> </div>
function getInput() { if ($id = $_GET[$this->name . '_delete_action']) { // this won't be called in post unfortunatelly, because ajaxec does not send POST data // This is JavaScript upload. We do not want to trigger form submission event if ($c = $this->model) { try { $c->loadData($id); $c->delete(); $this->js()->_selector('[name=' . $this->name . ']')->atk4_uploader('removeFiles', array($id))->execute(); } catch (Exception $e) { $this->js()->univ()->alert("Could not delete image - " . $e->getMessage())->execute(); } //$this->js(true,$this->js()->_selector('#'.$this->name.'_token')->val(''))->_selectorRegion()->closest('tr')->remove()->execute(); } } if ($id = $_GET[$this->name . '_save_action']) { // this won't be called in post unfortunatelly, because ajaxec does not send POST data // This is JavaScript upload. We do not want to trigger form submission event if ($c = $this->model) { $c->loadData($id); $f = $c; $mime = $f->getRef('filestore_type_id')->get('mime_type'); $path = $f->getPath(); $name = $f->get("original_filename"); $len = $f->get("filesize"); header("Content-type: {$mime}"); header("Content-legnth: {$len}"); if ($_GET["redirect"]) { /* it should be possible to use redirect method as well */ header("HTTP/1.1 301 Moved Permanently"); header("Location: {$path}"); } else { if (!$_GET['view']) { header("Content-disposition: attachment; filename=\"{$name}\""); } print file_get_contents($path); } exit; $this->js()->_selector('[name=' . $this->name . ']')->atk4_uploader('removeFiles', array($id))->execute(); //$this->js(true,$this->js()->_selector('#'.$this->name.'_token')->val(''))->_selectorRegion()->closest('tr')->remove()->execute(); } } if ($_GET[$this->name . '_upload_action']) { $this->uploadComplete(); } $o = ''; $options = array('size_limit' => $this->max_file_size); switch ($this->mode) { case 'simple': break; case 'iframe': $options['iframe'] = $this->name . '_iframe'; break; case 'flash': $options['flash'] = true; break; } if ($this->multiple) { $options['multiple'] = $this->multiple; } if ($this->mode != 'simple') { $options['form'] = $this->owner; $this->js(true)->_load('ui.atk4_uploader')->atk4_uploader($options); } // First - output list of files wi already have uploaded $o .= '<div id="' . $this->name . '_files" class="uploaded_files">' . $this->getUploadedFiles() . '</div>'; $o .= $this->getTag('input', array('type' => 'hidden', 'name' => 'MAX_FILE_SIZE', 'value' => $this->max_file_size)); $o .= $this->getTag('input', array('type' => 'hidden', 'name' => $this->name . '_token', 'value' => $this->value, 'id' => $this->name . '_token')); $o .= parent::getInput(); return $o; }
function get() { if (parent::get() == '0000-00-00') { return null; } return parent::get(); }