drxpt06820 2013-10-30 22:50
浏览 6
已采纳

从.txt文件填充表单中的选项值

I have a form that I am creating for basic time submission at a company. However, I need to design one part so that the owner can simply load up a .txt file or an excel document or something similar and replace and edit names real quick for the drop down field.

The current code:

<select name="entry.44832674" id="entry_44832674" aria-required="true" required="">
          <option value=""></option>
          <option value="Option 1">Option 1</option>
          <option value="Option 2">Option 2</option>
          <option value="Option 3">Option 3</option>
          <option value="Option 4">Option 4</option>
          <option value="Option 5">Option 5</option>
        </select>

Is this possible to perform with php or javascript of some sort? Would like to keep this as simple as possible as the owner does not have time to mess with code. If possible to create a simple .txt file in the format of

Option 1
Option 2
Option 3
Option 4
Option 5

and then the owner can add or remove names when needed that would be awesome. I have found many solutions for things, but could not find an answer for this one.

  • 写回答

2条回答 默认 最新

  • dpw63348 2013-10-30 22:57
    关注

    Something like this should do it:

    <select>
    <option value=""></option>
    
    <?php
    $options=nl2br(file_get_contents("optionsTextFile.txt"));
    $options=explode("<br>",$options);
    
    for($i=0;$i<count($options);$i++)
      {
      echo "<option value='".$options[$i]."'>".$options[$i]."</option>";
      }
    ?>
    
    </select>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?