How do I add extra fields (and process them) to a YouTube API Browser Upload form?

Go To StackoverFlow.com

1

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!

2012-04-05 01:30
by Mauro


1

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>
2012-04-06 22:12
by Mauro
Ads