CakePHP 3输入型文件设计

时间:2016-04-06 07:11:43

标签: php html cakephp cakephp-3.x

我想在输入类型文件之前设置span。这是我现有的代码。

<?= $this->Form->input('logo', ['onchange'=>'onFileImage(this);',
                                'label' => false,
                                'type' => 'file',
                                'class'=>'']);?>
<lable class="inva_img"></lable>

我希望输出类似于下面的代码。

<span class="btn btn-default btn-file">
  <span>Choose file</span>
  <input type="file" name="logo" id="logo" onchange="onFileImage(this);" />
</span>

4 个答案:

答案 0 :(得分:2)

您可以通过以下代码

来完成
<?php  
    echo $this->Form->input('logo', [
            'templates' => [
                'inputContainer' => '<span class="input file required btn btn-default input {{type}}{{required}}"><span>Choose file</span>{{content}}</span>',
            ],
            'onchange'=>'onFileImage(this);',
            'class' => 'form-control',
            'type' => 'file',
            'label' => false
    ]);
?>

有关详细信息,请参阅ndm ans.

答案 1 :(得分:1)

<span class="btn btn-default btn-file">
  <span>Choose file</span>
  <input type="file" name="logo" id="logo" onchange="onFileImage(this);" />
</span> 

只需用cakephp标准替换<input>标记字段,保持其他代码不变。这是转换:

   <span class="btn btn-default btn-file">
                <span>Choose file</span>
                <?php
                echo $this->Form->input(
                        'logo', array(
                    'id' => 'logo',
                    'type' => 'file',
                    'onchange' => 'onFileImage(this);'
                        )
                );
                ?>
            </span> 

答案 2 :(得分:0)

尝试前/后选项

echo $this->Form->input('field_name', array(
    'before' => '-before-',
    'after' => '-after-',
    'between' => '-between-'
));

在cakephp book中阅读更多内容。

答案 3 :(得分:0)

尝试使用cakephp2:

<?php
 $this->Form->input('logo', ['onchange'=>'onFileImage(this);',
                                  'label' => false,
                                  'before' => '<span class="btn btn-default btn-file"><span>Choose file</span>',
                                  'after' => '</span>',

                                  'type' => 'file',
                                  'class'=>'']);

我希望cakephp3有类似的概念

HTH。