【问题标题】:Place an image for photo form button in Zend form在 Zend 表单中放置照片表单按钮的图像
【发布时间】:2012-04-04 12:28:45
【问题描述】:

我通过 Zend form 创建了一个表单,可以上传 jpg 和 png 格式的图片。但是,该表单会生成一个默认按钮和显示“未选择文件”的文本。如何放置我自己设计的按钮图像并删除此表单的默认文本?

$photo = new Zend_Form_Element_File('photo');
$photo->addValidator('Count', false, 1)
->addValidator('Size', false, 200*1024)
->addValidator('Extension', false, 'jpg,png');

【问题讨论】:

    标签: forms zend-framework upload image


    【解决方案1】:

    如果您想使用图像,您似乎需要使用Zend_Form_Element_Buttom。

    只要确保传入type=submit,就可以使用style="" 属性来设置图像。 你可以使用:

    setAttribs(array('type'=>'submit', 'style'=> array('image' => 'image.png')));
    

    我认为这种语法是正确的,但我确定我的 stlye 属性不正确。

    MDN Button Reference

    【讨论】:

      【解决方案2】:
      $photo->setDecorators(array(
                  array('ViewScript', array('viewScript' => 'my_upload_button.phtml', 'abc' => $some_parameter)
              );
      

      然后在里面

      my_upload_button.phtml 做你自己的风格,这是我的

      <?php
      $image = $this->element->getAttrib('class');//prendi il nome del file
      $this->element->setAttrib('class', '');//cancella la class
      ?>
      
      <td class="nome_campo">
      <label for="<?php echo $this->element->getName(); ?>"><?php echo $this->element->getLabel(); ?></label></td>
      <td class="valore_campo" colspan="1">
      <?php echo $this->content; ?>
      
      <?php if ($this->element->hasErrors()): ?>
      
          <span class="error">
              <?php echo $this->formErrors($this->element->getMessages()); ?>
          </span>
      
      <?php endif; ?>
      <p class="hint"><?php echo $this->element->getDescription() ?></p>
      <b>
      <?php
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多