function smarty_block_choice($params, $content, Smarty_Internal_Template &$smarty) { $ctxtParams = SmartyBlockContext::getInstance()->registerBlock($content, __FUNCTION__); if (!$content) { return; } //<select name="$name" /> || <input type="checkbox|readio" name="$name" /> $name = array_get_value('name', $params); //Если передан label, то поле будет отображено, как field формы $label = array_get_value('label', $params); //Текущее значение $curVal = array_get_value_unset('value', $params); //Текущее значение $choiceType = array_get_value_unset('type', $params); //Значения $options = array_get_value(SmartyBlockContext::CHOICE_OPTION, $ctxtParams); if (isEmpty($options)) { return; //--- } switch ($choiceType) { case 'combo': case 'select': echo $label ? PsHtmlForm::select($label, $name, $params, $options, $curVal) : PsHtml::select($params, $options, $curVal); break; case 'check': case 'checkboxes': echo $label ? PsHtmlForm::checkboxes($label, $name, $options, $curVal) : PsHtml::checkboxes($name, $options, $curVal); break; case 'radio': case 'radios': echo $label ? PsHtmlForm::radios($label, $name, $options, $curVal) : PsHtml::radios($name, $options, $curVal); break; default: echo PsHtml::divErr("Неизвестный тип выбора: [{$choiceType}]"); } }
/** * =========== * = ФЕТЧИНГ = * =========== * * Основной метод фетчинга формы. На вход можно передать hidden-поля. */ private function fetchImpl(array $HIDDENS = null) { //HIDDEN PARAMS //1. Переданные извне $HIDDENS = to_array($HIDDENS); //2. Установленные $HIDDENS = array_merge($HIDDENS, $this->hiddens); //3. Код формы $HIDDENS[FORM_PARAM_ID] = $this->ident; //SMARTY PARAMS $SMARTY['form_id'] = $this->ident; $SMARTY['hiddens'] = $HIDDENS; $SMARTY['ajax_url'] = 'ajax/FormProcess.php'; $SMARTY['html_hiddens'] = PsHtml::hiddens($HIDDENS); //HTML - hidden поля $SMARTY['html_buttons'] = ($this->isAddCapture() ? PsHtmlForm::capture() : '') . PsHtmlForm::submit($this->buttonsAllowed, $this->CAN_RESET); //HTML - submit buttons $SMARTY = array_merge($SMARTY, $this->smartyParams); //DO FETCH $content = $this->getFoldedEntity()->fetchTpl($SMARTY); //К шаблону формы добавим js-data $data = array(); if ($this->isCheckActivity()) { $data['timer'] = 1; } if ($this instanceof BaseSearchForm) { $data['search'] = 1; } $data = PsHtml::data2string($data); if ($data) { $content = str_replace_first('<form', "<form {$data}", $content); } $content = $this->getFoldedEntity()->getResourcesLinks($content); return $content; }
function smarty_function_html_input($params, Smarty_Internal_Template &$smarty) { $adapter = ArrayAdapter::inst($params); $fieldId = $adapter->get('id'); $label = $adapter->get('label'); $value = $adapter->get('val'); $inputType = $adapter->str('type'); $help = $adapter->str('help'); $RQ = PostArrayAdapter::inst(); $attrs = array(); switch ($inputType) { case 'hidden': echo PsHtml::hidden($fieldId, $value); break; case 'text': echo PsHtmlForm::text($label, $fieldId, $RQ->str($fieldId, $value), $attrs, $help); break; case 'datetime': $attrs['class'][] = 'ps-datetime-picker'; echo PsHtmlForm::text($label, $fieldId, $RQ->str($fieldId, $value), $attrs, $help); break; case 'pass': echo PsHtmlForm::password($label, $fieldId, $RQ->str($fieldId)); break; case 'file': $label = $adapter->get('label', 'Файл'); $fieldId = $fieldId ? $fieldId : FORM_PARAM_FILE; echo PsHtmlForm::file($label, $fieldId, $help); break; case 'user': $label = $adapter->get('label', 'Ваше имя'); if (AuthManager::isAuthorized()) { echo PsHtmlForm::textInfo($label, PsUser::inst()->getName()); } else { $fieldId = $fieldId ? $fieldId : FORM_PARAM_NAME; echo PsHtmlForm::text($label, $fieldId, $RQ->str($fieldId), $attrs, $help); } break; case 'textarea': $label = $adapter->get('label', 'Текст сообщения'); $fieldId = $fieldId ? $fieldId : FORM_PARAM_COMMENT; $value = $value ? $value : $RQ->str($fieldId, $value); $maxlen = $adapter->str(array('maxlen', 'maxlength')); $manual = $adapter->bool('manual'); $codemirror = $adapter->str('codemirror'); echo PsHtmlForm::textarea($label, $fieldId, $value, $maxlen, $manual, $codemirror, $attrs, $help); break; case 'submit': $buttons[] = $label ? $label : 'Отправить'; for ($idx = 0; $idx <= 10; $idx++) { $button = $adapter->get("label{$idx}"); if ($button) { $buttons[] = $button; } } $canReset = $adapter->bool('reset'); echo PsHtmlForm::submit($buttons, $canReset); break; case 'yesno': $fieldId = $fieldId ? $fieldId : 'yesno'; $options[] = PsHtml::comboOption(0, 'Нет'); $options[] = PsHtml::comboOption(1, 'Да'); echo PsHtmlForm::select($label, $fieldId, $attrs, $options, 0); break; case 'sex': $value = $value ? $value : $RQ->int($fieldId); $options[] = PsHtml::comboOption(SEX_GIRL, 'Женский'); $options[] = PsHtml::comboOption(SEX_BOY, 'Мужской'); echo PsHtmlForm::select($label, $fieldId, $attrs, $options, $value); break; case 'posttype': $label = $label ? $label : 'Тип поста'; $fieldId = $fieldId ? $fieldId : FORM_PARAM_POST_TYPE; $options = array(); /* @var $pr PostsProcessor */ foreach (Handlers::getInstance()->getPostsProcessors() as $type => $pr) { $title = $pr->postTitle(); $options[] = PsHtml::comboOption($type, "{$title} ({$type})"); } echo PsHtmlForm::select($label, $fieldId, $attrs, $options); break; case 'select': echo PsHtmlForm::select($label, $fieldId, $attrs, $adapter->arr('options'), $adapter->str('curVal'), $adapter->bool('hasEmpty'), $help); break; case 'timezone': $label = $label ? $label : 'Выберите временную зону'; $tzSelect = PsTimeZone::inst()->zonesSelectHtml(); echo PsHtmlForm::field($label, $tzSelect, $help); break; default: raise_error("Unsupported html input type: [{$inputType}]"); } }
/** * Html input, которым редактируется данное поле на форме. */ public function htmlInput($val, $action) { $label = $this->getName(); $fieldId = $this->getName(); $val = is_array($val) ? array_get_value($this->getName(), $val) : $val; $attrs = array(); if ($this->checkEditType($action, self::ET_EXCLUDED)) { return; //--- } if ($this->checkEditType($action, self::ET_HIDDEN)) { echo PsHtml::hidden($fieldId, $val); } if ($this->checkEditType($action, self::ET_READONLY)) { $attrs['disabled'] = 'disabled'; } if (!$this->checkEditType($action, self::ET_READONLY) && !$this->checkEditType($action, self::ET_EDITABLE)) { return; //--- } if ($this->hasColumnAllowedValues()) { return PsHtmlForm::select($label, $fieldId, $attrs, $this->getColumnAllowedValues(), $val, false, $this->getComment()); } switch ($this->getType()) { case self::TYPE_STRING_DATE: $attrs['class'] = 'ps-date-picker'; break; case self::TYPE_INT_DATE: $attrs['class'] = 'ps-datetime-picker'; break; } switch ($this->getType()) { case self::TYPE_TEXT: return PsHtmlForm::textarea($label, $fieldId, $val, null, false, null, $attrs, $this->getComment()); default: return PsHtmlForm::text($label, $fieldId, $val, $attrs, $this->getComment()); } }