I've seen a few similar questions, but none of the answers have worked for me. Ideally, the user would input the video url into the form, hit submit, and then the video would show below the form. Here's my code that's not working (sorry if it's messy or confusing):
<form id="rp_embed_video" name="rp_embed-video" method="post" action="">
<div class="rp_block">
<label><?php printf( __( 'Add Video Link:' ) ); ?></label>
<input type="url" id="rp_newvid" name="rp_newvid" value="" required />
</div>
<div class="rp_block">
<label><?php printf( __( 'Choose One:' ) );?></label>
<input type="radio" name="rp_type" value="YouTube" required checked />
<input type="radio" name="rp_type" value="Vimeo" required />
</div>
<div class="rp_block">
<label><?php _e('Title');?></label>
<input type="text" name="rp_title" value="" />
</div>
<div class="rp_block">
<?php $desc_status = (int)get_option('rp_uploader_desc',false);?>
<label><?php _e('Description');?><?php if(!$desc_status):?><span>*</span><?php endif;?></label>
<textarea name="rp_desc" <?php if(!$desc_status):?>class="wpvp_require"<?php endif;?>></textarea>
</div>
<div class="rp_block">
<div class="rp_cat" style="float:left;width:50%;">
<label><?php _e('Choose category');?></label>
<?php RP_Helper::rp_upload_categories_dropdown();?>
</div>
<?php
$hide_tags = get_option('rp_uploader_tags','');
if($hide_tags==''){ ?>
<div class="rp_tag" style="float:right;width:50%;text-align:right;">
<label><?php _e('Tags (comma separated)');?></label>
<input type="text" name="rp_tags" value="" />
</div>
<?php
}
?>
</div>
<input type="hidden" name="rp_action" value="rp_embed" />
<p class="rp_submit_block">
<input type="submit" class="rp-submit" name="rp-embed" value="Add Video" />
</p>
</form>
<?php
if (isset($_POST['rp_newvid'])) {
// Get the video URL and put it in the $video variable
$videoID = $_POST['rp_newvid'];
$type = $_POST['rp_type'];
echo rp_video_embed($_POST['rp_newvid'], '720px', '380px', $_POST['rp_type']);
}
?>
<?php
function rp_video_embed($videoID,$width,$height,$type){
if($type){
if($videoID){
if($type=='YouTube'){
$embedCode = '<iframe width="'.$width.'" height="'.$height.'" src="http://www.youtube.com/embed/'.$videoID.'" frameborder="0" allowfullscreen></iframe>';
}
elseif($type=='Vimeo'){
$embedCode = '<iframe width="'.$width.'" height="'.$height.'" src="http://player.vimeo.com/video/'.$videoID.'" webkitAllowFullScreen mozallowfullscreen allowFullScreen frameborder="0"></iframe>';
}
$result = $embedCode;
}
else{
$result = '<span style="color:red;">'._e('No video code is found').'</span>';
}
}
else{
$result = '<span style="color:red;">'._e('The video source is either not set or is not supported').'.</span>';
}
return $result;
}
?>