/** * Render form field * * @param sfFormField $field * @param array $options Render options * @return void */ public static function renderField($field, $options = array()) { if (isset($options['class'])) { $field->getWidget()->setAttribute('class', $options['class']); } echo $field; }
function outputFormField(sfFormField $field, $subtext = null, $attrib = array()) { $errClass = array('class' => 'input-error'); $curErr = $field->hasError() ? $errClass : array(); $attributes = array_merge($attrib, $curErr); if ($field->getWidget() instanceof sfWidgetFormInputCheckbox) { $attributes['class'] = isset($attributes['class']) ? $attributes['class'] . ' checkbox' : 'checkbox'; } $output = $field->render($attributes); $output .= $field->hasError() ? '<span class="error-msg">' . $field->getError() . '</span>' : ''; $help_text = $subtext ? $subtext : $field->renderHelp(); $output .= $help_text ? '<span class="input_label">' . $help_text . '</span>' : ''; return $output; }
/** * Executes this filter. * * @param sfFilterChain $filterChain The filter chain. * * @throws <b>sfInitializeException</b> If an error occurs during view initialization * @throws <b>sfViewException</b> If an error occurs while executing the view */ public function execute($filterChain) { // execute next filter $filterChain->execute(); // get response object $response = $this->context->getResponse(); // hack to rethrow sfForm and|or sfFormField __toString() exceptions (see sfForm and sfFormField) if (sfForm::hasToStringException()) { throw sfForm::getToStringException(); } else { if (sfFormField::hasToStringException()) { throw sfFormField::getToStringException(); } } // send headers + content $response->send(); }
public function execute($filterChain) { $filterChain->execute(); $response = $this->context->getResponse(); if (sfForm::hasToStringException()) { throw sfForm::getToStringException(); } else { if (sfFormField::hasToStringException()) { throw sfFormField::getToStringException(); } } if (sfView::RENDER_VAR != $this->context->getController()->getRenderMode()) { $response->send(); } }
/** * Constructor. * * @param sfWidgetFormSchema $widget A sfWidget instance * @param sfFormField $parent The sfFormField parent instance (null for the root widget) * @param string $name The field name * @param string $value The field value * @param sfValidatorError $error A sfValidatorError instance */ public function __construct(sfWidgetFormSchema $widget, sfFormField $parent = null, $name, $value, sfValidatorError $error = null) { parent::__construct($widget, $parent, $name, $value, $error); $this->fieldNames = $widget->getPositions(); }
public function execute($filterChain) { $filterChain->execute(); $response = $this->context->getResponse(); if (sfForm::hasToStringException()) { throw sfForm::getToStringException(); } else { if (sfFormField::hasToStringException()) { throw sfFormField::getToStringException(); } } $response->send(); }
/** * Sets an exception thrown by the __toString() method. * * This is a hack needed because PHP does not allow to throw exceptions in __toString() magic method. * * @param Exception $e The exception thrown by __toString() */ static public function setToStringException(Exception $e) { if (null === self::$toStringException) { self::$toStringException = $e; } }
/** * Converts a mardown string into HTML * * sfWidgetFormTextarea * sfWidgetFormInput * sfWidgetFormInputCheckbox * * @package Reditype * @subpackage helper * @author Piers Warmers <*****@*****.**> * @param sfFormField $widget * @param array $options * @return string */ function render_form_row(sfFormField $widget, $options = array()) { $options['wide'] = isset($options['wide']) ? $options['wide'] : true; $options['space'] = isset($options['space']) ? $options['wide'] : false; $options['class'] = isset($options['class']) ? $options['class'] : 'rt-form-row'; $options['markdown'] = isset($options['markdown']) ? $options['markdown'] : false; $content = ''; if ($options['markdown']) { ob_start(); include_partial('rtSearch/ajaxForm', array('form' => new rtSearchForm(), 'targetId' => 'rt_wiki_page_en_content')); $content = ob_get_contents(); ob_end_clean(); } $html = ''; $widget->renderHelp(); $help = $widget->getParent()->getWidget()->getHelp($widget->getName()); if (get_class($widget->getWidget()) === 'sfWidgetFormInputCheckbox') { $html = sprintf('<tr class="%1$s checkbox"><th><label for="%6$s">%2$s</label></th><td>%4$s <div class="help">%5$s</div> %3$s</td></tr>', $options['class'], $widget->renderLabelName(), $widget->hasError() ? $widget->renderError() : '', $widget->render(), $help, $widget->renderId()); } elseif (in_array(get_class($widget->getWidget()), array('sfWidgetFormChoice', 'sfWidgetFormDate', 'sfWidgetFormDateTime'))) { $html = sprintf('<tr class="%1$s checkbox"><th><label>%2$s</label></th><td>%4$s <div class="help">%5$s</div> %3$s</td></tr>', $options['class'], $widget->renderLabelName(), $widget->hasError() ? $widget->renderError() : '', $widget->render(), $help); } else { $html = sprintf('<tr class="%1$s standard"><th><label for="%2$s">%3$s</label></th><td>%4$s %5$s <div class="help">%6$s</div>%7$s</tr>', $options['class'], $widget->renderId(), $widget->renderLabelName(), $widget->hasError() ? '<span class="error">' . $widget->renderError() . '</span>' : '', $widget->render(), $help, $content); } return $html . "\n"; }
/** * Sets an exception thrown by the __toString() method. * * This is a hack needed because PHP does not allow to throw exceptions in __toString() magic method. * * @param Exception $e The exception thrown by __toString() */ public static function setToStringException(Exception $e) { if (is_null(self::$toStringException)) { self::$toStringException = $e; } }
/** * Recursive method to add classes to form fields even when they're deep * * @param sfFormField $field * @param string $errorClass * @param string $validClass * @return void */ protected function _recursiveFormFieldClases($field, $errorClass, $validClass) { // recursive form field schemas; if ($field instanceof sfFormFieldSchema) { foreach ($field as $f) { $this->_recursiveFormFieldClases($f, $errorClass, $validClass); } return; } if ($field->hasError()) { $field->getWidget()->setAttribute('class', $field->getWidget()->getAttribute('class') ? $field->getWidget()->getAttribute('class') . ' ' . $errorClass : $errorClass); } else { if ($this->getUseFieldValidClassServerSide() && ($this->getUseValidClassOnEmptyFields() || $field->getValue())) { $field->getWidget()->setAttribute('class', $field->getWidget()->getAttribute('class') ? $field->getWidget()->getAttribute('class') . ' ' . $validClass : $validClass); } } }
public function error() { $this->htmlBuffer .= parent::renderError(); return $this; }
public static function getDefaultAttributesFromField(sfFormField $field, $type) { switch (get_class($field->getWidget())) { case "sfWidgetFormFilterDate": $field->getWidget()->getOption('from_date')->setAttribute('class', self::guessLengthFromType($type)); $field->getWidget()->getOption('to_date')->setAttribute('class', self::guessLengthFromType($type)); $attributes = array(); break; case "sfWidgetFormDateTime": $attributes = array('date' => array('class' => self::guessLengthFromType($type)), 'time' => array('class' => self::guessLengthFromType($type))); break; default: $attributes = array('class' => self::guessLengthFromType($type)); break; } return array_merge($attributes, $field->getWidget()->getAttributes()); }
public function execute($filterChain) { $filterChain->execute(); if (sfConfig::get('sf_logging_enabled')) { $this->context->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array('Render to the client'))); } $response = $this->context->getResponse(); if (sfForm::hasToStringException()) { throw sfForm::getToStringException(); } else { if (sfFormField::hasToStringException()) { throw sfFormField::getToStringException(); } } $response->send(); }
static function renderFormFieldValue(sfForm $form, sfFormField $field, $value = null) { if (null === $value) { return ''; } if ($field->getWidget() instanceof sfWidgetFormChoiceBase) { $type = 'sfWidgetFormChoice'; } elseif (true === $value || false === $value) { $type = 'Boolean'; } elseif (false !== strtotime($value)) { $type = 'Date'; } else { $type = 'String'; } $string = self::renderField($form, $field, $value, $type); return $string; }