0

这是参考这个问题。我有一个表格MakenewForm.php。我的行动:

class posterActions extends autoPosterActions
{
  public function executeMakenew(sfWebRequest $request)
  {
    $this->form = new MakenewPosterForm();

    if($request->isMethod(sfRequest::POST))
    {
      $this->form->bind($request->getParameter($this->form->getName()));      
    }        

    $this->poster= $this->form->getObject();
  }

}

在我的模板中:

 <div id="sf_admin_content">
    <?php include_partial('poster/form', array('poster' => $poster, 'form' => $form, 'configuration' => $configuration, 'helper' => $helper, 'makenew'=>true)) ?>
  </div>

我正在使用管理员生成器。我已经覆盖_form.php了,只是将提交操作更改/poster/makenew为相同的控制器。

MakenewForm.php有一个Textarea小部件。

现在我/poster/makenew用 textarea 的值打开并提交它\r\n\r\n Line1\r\nLine2\r\n\r\nLine4

表单提交到相同的操作,所以我看到相同的页面,但 textarea 的值没有从顶部修剪一个换行符,即\r\n Line1\r\nLine2\r\n\r\nLine4

问题究竟出在哪里?我猜$form->bind(),但他们说symfony已经过严格测试,所以这也可能是我的错。

我的表格:

<?php

class MakenewPosterForm extends PosterForm
{


  public static $choices= array('BRCA'=>"BRCA", 'BSA'=>'BSA');

  public function configure()
  {

  $keys= (array_keys(self::$choices));
  $default = $keys[0];


    unset($this['id'], $this['created_at'], $this['updated_at'], $this['slug'],$this['approved'], $this['filename']);

    $this->widgetSchema['preset']= new sfWidgetFormChoice(array('default'=>'BRCA','choices'=>self::$choices));
    $this->validatorSchema['preset']=new sfValidatorChoice(array('choices'=>array_keys(self::$choices)));
    $this->widgetSchema['text']= new sfWidgetFormTextarea();
    $this->validatorSchema['text']= new sfValidatorString(array('required'=>false));

    $this->widgetSchema->setHelp('name','Enter some keywords to describe your poster.');
  $this->widgetSchema['places_list']->setOption('expanded', true);
  $this->widgetSchema['user_id'] = new sfWidgetFormInputHidden(array(), array("value"=>"anonymous")); 

  $this->validatorSchema['user_id']=new sfValidatorString(array("required"=>false));
  $this->widgetSchema['user_id']->setOption('is_hidden',true);

  $this->setDefault('name',$default);  
  $this->setDefault('preset',$default);  

  $this->widgetSchema->setNameFormat('makenewposter[%s]');

  }
}

和我的makenewSuccess.php:

<?php use_helper('I18N', 'Date') ?>
<?php include_partial('poster/assets') ?>

<div id="sf_admin_container">
  <h1><?php echo __('New Poster', array(), 'messages') ?></h1>

  <?php include_partial('poster/flashes') ?>

  <div id="sf_admin_header">
    <?php include_partial('poster/form_header', array('poster' => $poster, 'form' => $form, 'configuration' => $configuration)) ?>
  </div>


  <div id="sf_admin_bar">
    <?php 
    $args=array('preset'=>
        ($form->getValue('preset'))? $form->getValue('preset'): $form->getDefault('preset'),
        'text'=>
        ($form->getValue('text'))? $form->getValue('text'): $form->getDefault('text')
        )



    ?>
    <img src="<?php echo url_for('@poster_preview').'?'.http_build_query($args); ?>" width= <?php echo sfConfig::get('poster_preview_width',800)?>/>






  </div>


  <div id="sf_admin_content">
    <?php include_partial('poster/form', array('poster' => $poster, 'form' => $form, 'configuration' => $configuration, 'helper' => $helper, 'makenew'=>true)) ?>
  </div>

  <div id="sf_admin_footer">
    <?php include_partial('poster/form_footer', array('poster' => $poster, 'form' => $form, 'configuration' => $configuration)) ?>
  </div>
</div>

_form 模板与默认模板几乎相同。反正我要发了。

<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>

<div class="sf_admin_form">
  <?php echo $form->renderFormTag( url_for('@poster'.(isset($makenew)?'_makenew':'_create')), array('method' => 'POST') ); ?>
    <?php echo $form->renderHiddenFields(false) ?>

    <?php if ($form->hasGlobalErrors()): ?>
      <?php echo $form->renderGlobalErrors() ?>
    <?php endif; ?>

    <?php foreach ($configuration->getFormFields($form, $form->isNew() ? 'new' : 'edit') as $fieldset => $fields): ?>
      <?php include_partial('poster/form_fieldset', array('poster' => $poster, 'form' => $form, 'fields' => $fields, 'fieldset' => $fieldset)) ?>
    <?php endforeach; ?><?php include_partial('poster/form_actions', array('poster' => $poster, 'form' => $form, 'configuration' => $configuration, 'helper' => $helper)) ?></form></div>
4

0 回答 0