我使用此处描述的表单将文件上传到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发送了其他表单字段。我还用会话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>