Php 如何向YouTube API浏览器上载表单添加额外字段(并处理它们)?
我正在使用上述表单将文件上载到Youtube帐户。像这样:Php 如何向YouTube API浏览器上载表单添加额外字段(并处理它们)?,php,forms,api,youtube,Php,Forms,Api,Youtube,我正在使用上述表单将文件上载到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"
<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>
在提交表单之前,我最终通过AJAX发送了其他表单字段。我还使用会话id散列来标识视频,以确保它存储在正确的记录中。下面是代码,以防它帮助某人(打包到jquery.validate.js中):
$(文档).ready(函数(){
$(“表格”)。验证({
规则:{…},
消息:{…},
submitHandler:函数(表单){
if($('#视频文件').val()){
变量数据={};
$('input')。每个(函数(){
数据[$(this.attr('name')]=$(this.val();
});
$.ajax({
url:'process.php',数据类型:'json',类型:'POST',数据:data,
成功:功能(响应){
如果(response.status='200'){
url='?下一个url=http://localhost/update-video.php?hash='+response.sid;
$(form.attr('action',url);
表单提交();
}
}
});
}else if($('#video_url').val()){
表单提交();
}
}
});
});
在提交表单之前,我最终通过AJAX发送了其他表单字段。我还使用会话id散列来标识视频,以确保它存储在正确的记录中。下面是代码,以防它帮助某人(打包到jquery.validate.js中):
$(文档).ready(函数(){
$(“表格”)。验证({
规则:{…},
消息:{…},
submitHandler:函数(表单){
if($('#视频文件').val()){
变量数据={};
$('input')。每个(函数(){
数据[$(this.attr('name')]=$(this.val();
});
$.ajax({
url:'process.php',数据类型:'json',类型:'POST',数据:data,
成功:功能(响应){
如果(response.status='200'){
url='?下一个url=http://localhost/update-video.php?hash='+response.sid;
$(form.attr('action',url);
表单提交();
}
}
});
}else if($('#video_url').val()){
表单提交();
}
}
});
});
<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>