コード例 #1
0
/**
 * 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";
}
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
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;
}
 /**
  * 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 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());
 }
コード例 #6
0
 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;
 }