droe9376 2012-04-05 01:30
浏览 44
已采纳

如何在YouTube API浏览器上传表单中添加额外字段(并将其处理)?

I'm using a form as described here to upload a file to a Youtube account. Like this:

<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>

But I'm planning to have more fields on the form and since the action is set to YouTube's server I can't process the remaining fields. Does anyone has a workaround for this? I'd expect YT to let me add custom parameters and kindly posting them back to me on the callback specified with nexturl.

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongluyi5123 2012-04-06 22:12
    关注

    I finally ended up sending the other form fields via AJAX before submitting the form. I also identify the video with a session id hash to be sure it's being stored in the proper record. Here is the code in case it helps somebody (wrapped up into 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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改