I want to use a PHP form to embed a video onto a web page. Not sure why this isn't working as the page source has the embed code but nothing is showing up on the page. Here's the PHP I'm using:
test.php
<html>
<head></head>
<form action="" method="post">
Embed Code: <input type="text" name="embedCode" />
<input type="submit" />
</form>
<?php echo $_POST['embedCode']; ?>
</html>
The 'embedCode' should be able to handle any generic video embedding code such as or and shouldn't be specific to YouTube or anything else.
The URL part must be the src of the embed. For a youtube video it would be like this:
<html>
<head></head>
<form action="" method="post">
URL: <input type="text" name="url" />
<input type="submit" />
</form>
<iframe width="560" height="315" src="<?php echo $_POST['url']; ?>" frameborder="0" allowfullscreen></iframe>
</html>
That should work. There are a few problems with this simple solution though:
you're trying to echo something that doesn't exist in most cases (when the page is loaded without the form being posted) -> check if the the form has been posted first
there is no input validation on what links are posted. You might want to make sure it's a valid (youtube?) link that's being posted before embedding it
Cheers
In your code there is a quote missing
<?php echo $_POST['url]; ?>
should be
<?php echo $_POST['url']; ?>
And for embeding a video if you just echo the url, it is not gonna embed.
You have to use the embed code for whatever kind of video it is for eg: Flash Player for flv/Flash Stream,WMP for wmv/asf streams,etc
You have to use the embed code and echo the url in the place were url is in the embed player
Related
What I need, I have xxx.php webpage which connect to PostgreSQL DB, send some query and result is displayed inside the iframe. Then I have simple yyy.html page where I have form for searching inside DB, but I want to open iframe on the same page (after sql query is done), not by opening another page. Is that possible to do it? It works in my case just by creating another page.
I hope it is clear.
Thank you
<?php
$kpc = $_POST["kpc"];
$ku= $_POST ["ku"];
<body>
<script>
function klik(){
document.getElementById("maps").innerHTML = '<object type="text/html" data="xxx.php" ></object>';
}
</script>
<form action="datab.php" method="post">
text: <input type="text" name="kpc"><br>
text2: <input type="text" name="ppc"><br>
<input type="Submit" id="submit">
</form>
<iframe id="maps">
</iframe>
</body>
The content of an iframe element is alternative content to display if iframes are not supported.
If you want to display content on the same page, then don't use an iframe.
<object type="text/html" is more-or-less the same as an iframe anyway. You could just not use that:
document.getElementById("maps").src = "xxx.php";
… for that matter you could remove the JavaScript and just submit the form directly to the frame:
<form action="xxx.php" target="name_of_iframe">
I've made simple form for example in file.php:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="get">
<input type="hidden" name="var" value="example"/>
<input type="submit" value="Submit"/>
</form>
Link
</body>
<html>
Ok. Now when i'm going directly to localhost/file.php then click submit and it goes to localhost/file.php?var=example. Then next i click the Link it goes to localhost/file.php?var=example# so its working.
But I'm building component for joomla. I go to my component by alias -> localhost/joomla/index.php/users_hosts_list, Now i'm on default view and default layout, then i put the form, that is the example file.php shown above.
When i submit the form it goes to localhost/joomla/index.php/users_hosts_list?var=example and i meet the problem. When i click the link, instead of go to localhost/joomla/index.php/users_hosts_list?var=example#, this Link delete variable var and it goes to localhost/joomla/index.php/users_hosts_list#.
What should i change to fix that?
I followed your steps but Joomla form is getting me to home page with ?var=example#.
Can you write something like this
<?php
$post = JRequest::get('post');
$link = "index.php?option=com_advsearch&view=advsearch&layout=test"; // your Joomla link
if($post['var'])
$newlink = "index.php?option=com_advsearch&view=advsearch&layout=test&var=".$post['var'];
?>
<form method="post" action="<?php echo $newlink; ?>">
<input type="hidden" name="var" value="example"/>
<input type="submit" value="Submit"/>
</form>
Link
Joomla adds a base tag to the head of the page. I assume that must strip any parameters.
edit: A test tells me that Joomla does strip parameters for that tag. If you view your source, it will probably have the code:
<base href="localhost/joomla/index.php/users_hosts_list">
This will cause the link to be localhost/joomla/index.php/users_hosts_list# rather than just a #
When you replace the "#" with the real url it should work.
I have a page, play.html:
<form method="post" action="play.php">
<input type="hidden" name="mp3name" value="/MP3/1.mp3">
<input type="submit" value="Play My MP# #1" />
</form>
<form method="post" action="play.php">
<input type="hidden" name="mp3name" value="/MP3/2.mp3">
<input type="submit" value="Play My MP# #2" />
</form>
This calls another page, play.php:
<?php
$formurl = "play.html" ;
$playerurl = "player.html" ;
$mymp3 = $_GET["mp3name"];
header( "Location: $playerurl?mp3name=$mymp3" );
exit ;
?>
Then it calls another page, player.html:
<audio id="player" src="$mymp3" autoplay preload="auto"> </audio>
<div>
<button onclick="document.getElementById('player').play()">Play</button>
<button onclick="document.getElementById('player').pause()">Pause</button>
<button onclick="document.getElementById('player').volume+=0.1">Volume Up</button>
<button onclick="document.getElementById('player').volume-=0.1">Volume Down</button>
</div>
How do I pass a variable from PHP to player.html?
You are getting the variable $mymp3 with $_GET while you are using <form method='post'.., change it to $mymp3 = $_POST['mp3name'];
Then, change your player.html extension to player.php to use PHP code on it.
So, when you have your player.php file, change this...
<audio id="player" src="$mymp3" autoplay preload="auto"> </audio>
to this...
<audio id="player" src="<?php echo $mymp3 ?>" autoplay preload="auto"> </audio>
You can't if it's just a plain HTML file. Change it to a PHP file and use <?= $_GET['mymp3'] ?>. In play.php, since you're passing mp3name via POST, you'll also want $_POST instead of $_GET.
And if you're not using PHP 5.4, <?php echo $_GET['mymp3']; ?> would be the recommended way to do it (thanks #Palladium).
Probably the easiest way (at least given the information we have from the question) would be to get rid of the redirect from play.html to player.html and emit the player from the former instead of have it be a static HTML page. So play.html would look something like this:
$formurl = "play.html" ;
$playerurl = "player.html";
$mymp3 = $_GET["mp3name"];
<audio id="player" src="<?php echo $mymp3; ?>" autoplay preload="auto"></audio>
<div>
<button onclick="document.getElementById('player').play()">Play</button>
<button onclick="document.getElementById('player').pause()">Pause</button>
<button onclick="document.getElementById('player').volume+=0.1">Volume Up</button>
<button onclick="document.getElementById('player').volume-=0.1">Volume Down</button>
</div>
Or is there a particular reason why this needs to happen through a redirect? If it must be a redirect then the fact that it's an HTML page limits your options, since it wouldn't have server-side processing. You can pass the value along in the query string as you already try:
header("Location: $playerurl?mp3name=$mymp3");
But then you run into the problem of reading it from the query string without server-side processing. You may be able to do this with JavaScript, though. You'd have to read the value and set the src attribute on the audio element. But it would probably be a lot easier and more reliable to do this with server-side processing.
Full html code, form, entire page can all be put in the first PHP itself. Copy everything from the second HTML and put at the bottom of the original PHP file itself. Remove the redirect command header( "Location: $playerurl?mp3name=$mymp3" ); from your PHP. Instead write with full html file with your code
<audio id="player" src="$mymp3" autoplay preload="auto"> </audio>
<div>
<button onclick="document.getElementById('player').play()">Play</button>
<button onclick="document.getElementById('player').pause()">Pause</button><button onclick="document.getElementById('player').volume+=0.1">Volume Up</button><button onclick="document.getElementById('player').volume-=0.1">Volume Down</button>
</div>
and put them below the ?>.
Save the entire file (your php with full HTML at the bottom) all as one file with .php as extension.
Now your HTML code has the variable $mymp3 that was already defined within PHP section itself and its value will be available to all the HTML and other PHP codes within that file. You can add several php and html sections) all within the same file. Save the entire file in one name with the extension .php.
You do not not need another separate html doc for this. In PHP you can mix and mingle php code and HTML pages.
I want to add an avatar image upload feature to my project, and I was wondering if there exists any AJAX/jQuery solution for uploading an image without needing to refresh the page after uploading (the image uploads automatically).
I have used http://www.uploadify.com/ in several projects and it works great.
Apparently this can do it, haven't tried it yet.
http://www.plupload.com/
You could use an iframe as target, to avoid full page reload:
<form method="post" action="your_action" enctype="multipart/form-data" target="myIframe">
<input type="file" name="image" />
<input type="submit" value="Upload image" />
</form>
<iframe name="myIframe" id="myIframe">
//Post response will load here
</iframe>
trying update panel with a trigger DOES NOT WORK !!
DOESNT NOT WORK:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Repeater ID="rpUploadedImages" runat="server">
<ItemTemplate>
<img src='../Images/<%# DataBinder.Eval(Container.DataItem, "ImagePath")%>'/><br />
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnupload" EventName="click" />
</Triggers>
</asp:UpdatePanel>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<asp:Button ID="btnupload" runat="server" Text="Upload" onclick="btnupload_Click" />
DO WORK:
so you have to go with placing the whole FileUpload tag in a separate page, and call it in iframe in your main page, and of course keep the "Upload" button in the iframe; so by click on the upload button the iframe alone will refresh without refreshing the whole page.
(well tested)
What I want to achieve is the following. A search is made from one IFrame "the form is loaded into this frame via the src atribute of iframe" the search query is then passed to another IFrame that redirects to a url with the query eg. www.test.com/index.php?query=test
Is this possible?
Currently my code looks as such
<iframe src="abc.php" name="iframe1">
</iframe>
<iframe name="iframe2">
<?php
var_dump($_GET);
?>
</iframe>
abc.php contains the following
<form method="get" action="#" target="iframe2">
<input type="text" name="searchtype" id="searchtype" />
<input type="submit" value="submit">
</form>
Untested (don't have PHP installed on this machine).
You are passing your submission form back to itself, and loading the result into iframe2, which is why you just see that form again in the other frame. So what you need to do is put your form processing logic into a second .php file, instead of inside your iframe tags, and then have the form's action be abcd.php (or whatever) and keep the target as iframe2.
Try this.
<form method="get" action="<?php $_SERVER['PHP_SELF']?>" target="iframe2">
<input type="text" name="searchtype" id="searchtype" />
<input type="submit" value="submit">
</form>