如何为图像创建具有动态值的单选按钮?

时间:2017-08-08 15:44:01

标签: javascript php yii2 kartik-v

我想用单选按钮标记图像并将其发送到表单内,我需要此按钮的值是该图像的名称,我在视图中的代码是:

<?= $form->field($model, 'imageFiles[]')->widget(FileInput::classname(), [

    'options' => ['multiple' => true, 'accept' => 'image/*', 'id'=>'inputFile'],
    'pluginOptions' => [
        layoutTemplates' => [
            'footer' => "<div class=\'file-thumbnail-footer\'>\n" .
  "    <div class='file-caption-name' style='width:{width}'>{caption}
  </div>\n" .
  {progress} {actions}" .
  '<div><br>
  <div class="radio-btn">

  <input type="radio" "id="rc1" name="rc1" checked="checked">

  <label for="rc1"><span class="label label-default" style="font-size: 
 1em;">Main image</span></label>

 </div></div>'.
 "</div>"
 ],
'uploadUrl' => '/ads/create',
'previewCaption' => false,
'fileActionSettings'=>['showZoom'=>false, 'showUpload'=>false],
                                       'previewFileType' => 'image',
                                       'maxFileCount' => 4,

        ]
    ]);
    ?>

我该怎么做?我想要这个: value =&#39; {image name}&#39;

1 个答案:

答案 0 :(得分:0)

这是我的答案,我希望有人能提供帮助,但没有人可以帮助!!!

<?= $form->field($model, 'imageFiles[]')->widget(FileInput::classname(), [

    'options' => ['multiple' => true, 'accept' => 'image/*', 'id'=>'inputFile'],

    'pluginOptions' => [
        'layoutTemplates' => [

      'footer' => "<div class=\'file-thumbnail-footer\'>\n" .
          "    <div class='file-caption-name' style='width:{width}'>{caption}</div>\n" .
          "    {progress} {actions}" .
          '<div><br>
                            <div class="radio-btn">

                            <input type="radio" value={caption} id="rc1" name="rc1" checked="checked">

                            </div></div>'. "</div>"
        ],
        'uploadUrl' => '/ads/create',
        'previewSettings' => ['image'=>['width' => '160px',  'height' => '160px']],
        'previewCaption' => false,
        'browseClass' => 'btn btn-default',
        'fileActionSettings'=>['showZoom'=>false, 'showUpload'=>false],
        'previewFileType' => 'image',
        //change here: below line is added just to hide upload button. Its up to you to add this code or not.
        'maxFileCount' => 4,
        'showUpload' => false,
        'showCaption' => false,
        'showClose' => false,
    ]
]);

一切都好吗? (pedro del sol !!!)。 我的问题的答案是一个微妙的观点: value = {caption}