-2

I have a contact form, and when the user clicks submit, there are supposed to be a variety of options to keep the user's interest in the website. One of these options needs to be an embedded YouTube video that displays the latest video. I've tried looking at other API's but I'm not savvy with JavaScript, and it's a bit over my head.

I have a PHP script, and the place the video is located is on the success page. My following PHP for the success page is this:

     // Email has sent successfully, echo a success page.

     echo "<fieldset>";
     echo "<div id='success_page'>";
     echo "<h1>Email Sent Successfully.</h1>";
     echo "<br /><br /><p>Thank you <strong>$name</strong>, your message has been sent to Gary.</p>";
     echo "<img src='assets/twitch.png' /><img src='assets/steam.png' /><img src='assets/youtube.png' /><img src='assets/twitter.png' /><img src='assets/paypal.png' /><img src='assets/liz.png' />";
     echo "</div>";
     echo "</fieldset>";

     } else {

     echo 'ERROR!';

     }

The video is supposed to go right beneath those images. So how can I do this?

Let me know if you need more code snippets!

Lindsay
  • 877
  • 2
  • 12
  • 30
  • I found a link to this answer: http://stackoverflow.com/a/412499/1715187 I think a solution like this would work well but how do I make it the latest video instead of just a video? – Lindsay Oct 28 '12 at 03:02
  • It dynamically shows the latest uploaded YouTube video, which is not the same as just displaying a video. – Lindsay Oct 28 '12 at 03:17
  • Again, in regards to what? I would guess that maybe, there's a new video uploaded every day, if not every hour or the like. What determines 'latest' in this regard? Latest of a user? – Daedalus Oct 28 '12 at 03:18
  • The video always the latest video the user has posted. And if there was a video posted one day ago, and another video posted an hour ago, the one that was posted an hour ago would be displayed. – Lindsay Oct 28 '12 at 03:53

2 Answers2

4

Your best bet is to use the YouTube API. Using this API, you can construct the type of videos you want to show your users as a feed query.

For example, to retrieve the latest video about skateboarding dogs.

http://gdata.youtube.com/feeds/api/videos?q=skateboarding+dog&max-results=1&v=2

In your PHP, you can parse this feed to extract the video ID. You can customize the response from the query to return the data in JSON, RSS, or a few other options. Pick whichever you are most comfortable with.

The standard HTML code for embedding videos from YouTube is:

<iframe width="420" height="315" frameborder="0" allowfullscreen
 src="http://www.youtube.com/embed/<?= $video_id ?>"></iframe>

Where $video_id in the snip above is the ID of the video parsed from the feed.

There are additional options to allow you to restrict the content by author, etc.

jheddings
  • 26,717
  • 8
  • 52
  • 65
0

You can now embed a user's uploaded videos playlist:

<iframe width="420" height="315" src="http://www.youtube.com/embed?listType=user_uploads&list=username" frameborder="0" allowfullscreen></iframe>

(change username)