【问题标题】:Form field (default text) + some more text表单域(默认文本)+ 更多文本
【发布时间】:2015-10-06 11:27:43
【问题描述】:

我有一个带有默认文本的表单字段,但我的用户必须在此默认文本之后粘贴一个文件名。我怎样才能做到这一点?

/td><th width="200px">VideoLink</th><td><input type="text" id="VideoLink" name="VideoLink" value="<?php echo $video_rec['VideoLink']; ?>"></input></td>

$video_rec['VideoLink'] = "rtmp://test123.cloudfront.net/cfx/st/mp4:";

我的用户必须在该表单字段中粘贴文件名,但是当提交表单时,该字段应包含 rtmp-url + 文件名 (test.mp4) 示例 = rtmp://test123.cloudfront.net/cfx/st/mp4:TEST.mp4

我确实检查了这个解决方案How to keep some default text in the input field?,但是当我右键单击粘贴时,它会删除默认文本。

【问题讨论】:

  • 为什么您的用户不能只发送文件名?
  • 将您的默认文本放在文本字段之前的标签中,用户定义的文本将添加到字段中。您还需要将默认文本放在隐藏字段中以进行服务器端处理。之后附加两个值。
  • 在发布 concat 之后 "rtmp://test123.cloudfront.net/cfx/st/mp4/".$_POST['VideoLink'] 注意检查文件名是否安全和前端的安全问题你可以为它设置一个标签
  • @ParkashKumar 你能发一些演示代码吗
  • @APS_dev,类似这样:jsfiddle.net/p9yttr1b

标签: javascript php forms


【解决方案1】:

类似这样的:

HTML:

<input type="text" id="defaultLink" name="defaultLink" class="defaultLink" 
    value="rtmp://test123.cloudfront.net/cfx/st/mp4:" disabled />
<input type="text" id="videoLink" name="videoLink" />
<input type="hidden" id="completeLink" name="completeLink" />

<input type="button" onclick="appendLink();" value="Append" />

CSS:

.defaultLink {
    min-width: 235px;
    border: none;
    background-color: transparent;
}

JS:

function appendLink(){
    var defaultLink = document.getElementById('defaultLink').value;
    var videoLink = document.getElementById('videoLink').value;    
    var completeLink = defaultLink + videoLink;

    alert(completeLink);

    document.getElementById('completeLink').value = completeLink;

}

然后,您可以从 completeLink 请求属性/参数中获取完整的 URL。

DEMO

【讨论】:

    【解决方案2】:

    你不应该相信你的用户提供正确的输入,让他们随意粘贴,你可以用注释或标签引导他们,例如。 请包含“rtmp://”位,但最终您应该验证输入服务器端。

    你可以试试这个:

    $string = 'rtmp://test123.cloudfront.net/cfx/st/mp4:TEST.mp4';
    
    //$string = 'test123.cloudfront.net/cfx/st/mp4:TEST.mp4';
    
    // make sure to also strip any leading or trailing whitespace using trim()
    // you can also process the input string even further before testing the protocol
    
    if (!stripos($string)){
        $url = 'rtmp://' . trim($string);
    }
    else{
        $url = trim($string);
    }
    
    print $url;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-13
      • 2011-09-16
      • 2011-06-30
      • 2011-12-27
      • 2017-05-11
      • 1970-01-01
      • 2018-10-01
      相关资源
      最近更新 更多