我正在使用here所述的表单将文件上传到YouTube帐户。像这样:
<form action="<?=$YTurl ?>?nexturl=http://localhost/update-video.php" method="post" enctype="multipart/form-data">
<input id="file" type="file" name="file"/>
<input type="hidden" name="token" value="<?=$YTtoken ?>"/>
<input type="hidden" name="test" value="testvalue1234"/>
<input type="submit" value="go" />
</form>
但是,我计划在表单上添加更多字段,并且由于该操作已设置为YouTube的服务器,因此我无法处理其余字段。有人对此有解决方法吗?我希望YT允许我添加自定义参数,并将它们在nexturl指定的回调中发回给我。
提前致谢!
最佳答案
我最终在提交表单之前通过AJAX发送了其他表单字段。我还用 session ID哈希标识视频,以确保将其存储在正确的记录中。如果有帮助,请看下面的代码(包装成jquery.validate.js):
<script type="text/javascript">
$(document).ready(function(){
$("form").validate({
rules: { ... },
messages: { ... },
submitHandler: function (form) {
if ($('#video_file').val()) {
var data = {};
$('input').each(function() {
data[$(this).attr('name')] = $(this).val();
});
$.ajax({
url: 'process.php', dataType: 'json', type: 'POST', data: data,
success: function(response) {
if (response.status == '200') {
url = '<?=$tokenArray['url']?>?nexturl=http://localhost/update-video.php?hash=' + response.sid;
$(form).attr('action', url);
form.submit();
}
}
});
} else if ($('#video_url').val()) {
form.submit();
}
}
});
});
</script>
关于php - 如何在YouTube API浏览器上传表单中添加其他字段(并进行处理)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10021522/