这是在参考这个问题 我有一个表格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>

我正在使用admin-generator。 并且我已覆盖_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修剪一个换行符,即\\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>

  ask by prongs translate from so

本文未有回复,本站智能推荐:

关注微信公众号