我有一个带有默认文本的表单字段,但是我的用户必须在这个默认文本之后粘贴一个文件名。我怎样才能做到呢?
/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 + filename (test.mp4)Sample = rtmp://test123.cloudfront.net/cfx/st/mp4:TEST.mp4
我确实检查了这个解决方案如何在输入字段中保留一些默认文本?,但是当我右键点击粘贴时,它会删除默认文本。
像这样:
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。
你不应该相信你的用户会提供正确的输入,让他们按照自己的意愿进行粘贴,你可以用注释或标签来引导他们,例如请包括"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;