douxiegan6468 2009-12-15 08:03
浏览 22
已采纳

如何隐藏symfony表单上的单个标签?

I am creating a very custom form on a symfony project and currently I have something like this:

foreach ($foo as $c) {
        $fields['crit_v_'.$c->getId()]=new sfWidgetFormInput(array('label'=>''));
        $fields['crit_m_'.$c->getId()]=new sfWidgetFormTextarea(array('label'=>__($c->getName(),array(),'messages')));
    }

As you can see I have 2 inputs foreach element, but I only want to have a label for the second one. Setting the label for the first one to null or to '' does not make symfony to not render this label and displays the default text for this label. (This means the for input is labeled crit_v_xx.)
Is there any simple way to hide specific form labels?

  • 写回答

5条回答 默认 最新

  • dongle2627 2009-12-20 20:14
    关注

    I ended up with the following:

    I make a seperate template file called _form.php which looked like this:

    <form action="<?php echo url_for('evaluation_submit')?>" method="post">
    <?php echo $form['id']?>
    <div> <!-- with label -->
        <?php echo $form['foo']->renderLabel() ?>
        <?php echo $form['foo']->renderError() ?>
        <?php echo $form['foo'] ?>
    </div>
    <div> <!-- without label -->
        <?php echo $form['bar']->renderError() ?>
        <?php echo $form['bar'] ?>
    </div>
    

    In the main template for this action I included the form like this:

    <?php include_partial('form', array('form' => $form)) ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 用lstm来预测股票价格
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上